mirror of
https://github.com/nuttytree/ESPHome-Devices.git
synced 2024-08-30 18:12:19 +00:00
Gosund dimmer
This commit is contained in:
parent
14abb72561
commit
85f3064782
3
common/binary_sensor/day_night.yaml
Normal file
3
common/binary_sensor/day_night.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
platform: homeassistant
|
||||
id: day_night
|
||||
entity_id: input_boolean.day_night
|
28
common/binary_sensor/gosund_dimmer_button.yaml
Normal file
28
common/binary_sensor/gosund_dimmer_button.yaml
Normal file
@ -0,0 +1,28 @@
|
||||
platform: gpio
|
||||
pin:
|
||||
number: GPIO4
|
||||
inverted: true
|
||||
id: gosund_button
|
||||
on_multi_click:
|
||||
- timing:
|
||||
- ON for at most 1s
|
||||
- OFF for at most .4s
|
||||
- ON for at most 1s
|
||||
- OFF for at least 0.1s
|
||||
then:
|
||||
- script.execute: double_tap
|
||||
- timing:
|
||||
- ON for at most 1s
|
||||
- OFF for at least 0.4s
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
light.is_off: gosund_light
|
||||
then:
|
||||
- light.turn_on:
|
||||
id: gosund_light
|
||||
brightness: !lambda |-
|
||||
return (id(day_night) ? ${day_level} : ${night_level}) / 100.0;
|
||||
else:
|
||||
- light.turn_off: gosund_light
|
||||
- script.execute: single_tap
|
14
common/common_gosund_dimmer.yaml
Normal file
14
common/common_gosund_dimmer.yaml
Normal file
@ -0,0 +1,14 @@
|
||||
<<: !include wifi.yaml
|
||||
<<: !include api.yaml
|
||||
<<: !include ota.yaml
|
||||
|
||||
<<: !include status_led/gosund_dimmer.yaml
|
||||
|
||||
light:
|
||||
- !include light/gosund_dimmer.yaml
|
||||
|
||||
output:
|
||||
- !include output/gosund_dimmer_led.yaml
|
||||
|
||||
uart:
|
||||
- !include uart/gosund_dimmer.yaml
|
8
common/light/gosund_dimmer.yaml
Normal file
8
common/light/gosund_dimmer.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
platform: custom
|
||||
lambda: |-
|
||||
auto gosund_light = new GosundSW2Light(gosund_uart, gosund_dimmer_led);
|
||||
App.register_component(gosund_light);
|
||||
return {gosund_light};
|
||||
lights:
|
||||
- id: gosund_light
|
||||
name: ${device_name}
|
5
common/output/gosund_dimmer_led.yaml
Normal file
5
common/output/gosund_dimmer_led.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
platform: gpio
|
||||
id: gosund_dimmer_led
|
||||
pin:
|
||||
number: GPIO13
|
||||
inverted: true
|
4
common/status_led/gosund_dimmer.yaml
Normal file
4
common/status_led/gosund_dimmer.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO12
|
||||
inverted: true
|
4
common/uart/gosund_dimmer.yaml
Normal file
4
common/uart/gosund_dimmer.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
id: gosund_uart
|
||||
rx_pin: GPIO3
|
||||
tx_pin: GPIO1
|
||||
baud_rate: 115200
|
44
dining_room_light.yaml
Normal file
44
dining_room_light.yaml
Normal file
@ -0,0 +1,44 @@
|
||||
substitutions:
|
||||
device_id: dining_room_light
|
||||
device_name: Dining Room Light
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret dining_room_light_ip
|
||||
ota_pwd: !secret dining_room_light_ota_pwd
|
||||
api_pwd: !secret dining_room_light_api_pwd
|
||||
ap_wifi_pwd: !secret dining_room_light_ap_wifi_pwd
|
||||
|
||||
day_level: '100'
|
||||
night_level: '10'
|
||||
|
||||
esphome:
|
||||
<<: !include common/esphome.yaml
|
||||
includes:
|
||||
- gosund_sw2_dimmer.h
|
||||
|
||||
<<: !include common/common_gosund_dimmer.yaml
|
||||
<<: !include common/logger/logger_debug_no_serial.yaml
|
||||
|
||||
binary_sensor:
|
||||
- !include common/binary_sensor/status.yaml
|
||||
- !include common/binary_sensor/day_night.yaml
|
||||
- !include common/binary_sensor/gosund_dimmer_button.yaml
|
||||
|
||||
sensor:
|
||||
- !include common/sensor/uptime.yaml
|
||||
- !include common/sensor/wifi.yaml
|
||||
|
||||
switch:
|
||||
- !include common/switch/restart.yaml
|
||||
|
||||
text_sensor:
|
||||
- !include common/text_sensor/version.yaml
|
||||
- !include common/text_sensor/wifi.yaml
|
||||
|
||||
script:
|
||||
- id: single_tap
|
||||
then:
|
||||
- logger.log: "Single Tap"
|
||||
- id: double_tap
|
||||
then:
|
||||
- logger.log: "Double Tap"
|
56
gosund_sw2_dimmer.h
Normal file
56
gosund_sw2_dimmer.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
#include "esphome.h"
|
||||
#include "esphome/components/output/binary_output.h"
|
||||
#include "esphome/components/light/light_state.h"
|
||||
#include "esphome/components/light/light_output.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
|
||||
class GosundSW2Light : public Component, public uart::UARTDevice, public light::LightOutput {
|
||||
public:
|
||||
GosundSW2Light(UARTComponent *uart, BinaryOutput *indicator) : UARTDevice(uart) { indicator_ = indicator; }
|
||||
void setup() override {}
|
||||
void loop() override;
|
||||
LightTraits get_traits() override;
|
||||
void setup_state(light::LightState *state) override { state_ = state; }
|
||||
void write_state(light::LightState *state) override;
|
||||
|
||||
protected:
|
||||
light::LightState *state_;
|
||||
output::BinaryOutput *indicator_;
|
||||
};
|
||||
|
||||
LightTraits GosundSW2Light::get_traits() {
|
||||
auto traits = LightTraits();
|
||||
traits.set_supports_brightness(true);
|
||||
return traits;
|
||||
}
|
||||
|
||||
void GosundSW2Light::write_state(light::LightState *state) {
|
||||
float brightness;
|
||||
state->current_values_as_brightness(&brightness);
|
||||
uint8_t command;
|
||||
|
||||
if (brightness == 0.0f) {
|
||||
command = 0;
|
||||
indicator_->turn_off();
|
||||
}
|
||||
else {
|
||||
command = (127.0 * brightness) + 0x80;
|
||||
indicator_->turn_on();
|
||||
}
|
||||
|
||||
this->write_byte(command);
|
||||
}
|
||||
|
||||
void GosundSW2Light::loop() {
|
||||
if (this->available() >= 5) {
|
||||
uint8_t data[5];
|
||||
if (this->read_array(data, 5)) {
|
||||
auto brightness = float(data[1] == 0 ? 1 : data[1] > 100 ? 100 : data[1]) / 100.0;
|
||||
auto call = this->state_->make_call();
|
||||
call.set_brightness(brightness);
|
||||
call.set_transition_length(0);
|
||||
call.perform();
|
||||
}
|
||||
}
|
||||
}
|
44
living_room_lights.yaml
Normal file
44
living_room_lights.yaml
Normal file
@ -0,0 +1,44 @@
|
||||
substitutions:
|
||||
device_id: living_room_lights
|
||||
device_name: Living Room Lights
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret living_room_lights_ip
|
||||
ota_pwd: !secret living_room_lights_ota_pwd
|
||||
api_pwd: !secret living_room_lights_api_pwd
|
||||
ap_wifi_pwd: !secret living_room_lights_ap_wifi_pwd
|
||||
|
||||
day_level: '100'
|
||||
night_level: '10'
|
||||
|
||||
esphome:
|
||||
<<: !include common/esphome.yaml
|
||||
includes:
|
||||
- gosund_sw2_dimmer.h
|
||||
|
||||
<<: !include common/common_gosund_dimmer.yaml
|
||||
<<: !include common/logger/logger_debug_no_serial.yaml
|
||||
|
||||
binary_sensor:
|
||||
- !include common/binary_sensor/status.yaml
|
||||
- !include common/binary_sensor/day_night.yaml
|
||||
- !include common/binary_sensor/gosund_dimmer_button.yaml
|
||||
|
||||
sensor:
|
||||
- !include common/sensor/uptime.yaml
|
||||
- !include common/sensor/wifi.yaml
|
||||
|
||||
switch:
|
||||
- !include common/switch/restart.yaml
|
||||
|
||||
text_sensor:
|
||||
- !include common/text_sensor/version.yaml
|
||||
- !include common/text_sensor/wifi.yaml
|
||||
|
||||
script:
|
||||
- id: single_tap
|
||||
then:
|
||||
- logger.log: "Single Tap"
|
||||
- id: double_tap
|
||||
then:
|
||||
- logger.log: "Double Tap"
|
Loading…
Reference in New Issue
Block a user