Open OnTarget600 opened 3 weeks ago
This is how I corrected the problem: `light:
fan:
I will post my full code in case someone is interested. I fixed the lights on by default problem and there is also the color temperature management and fix for 24.06 esphome update. Also added some sensor to monitor the connection. Labels are in french but you can easily translate it back to english
#Please edit name and IP (36)
substitutions:
name: fan-bureau
device_name: fan-bureau
fan_name: Brasseur
light_name: Plafonnier
temp_name: Brasseur-Temp
tmp117_name: "SkyFanDC TMP117"
skyfan_model: "SKY1203"
light_color: "Temperature de la couleur"
#packages:
# jimmy.easy_skyfandc: github://jeggleston1981/skyfandc/micro_skyfan2.yaml
esphome:
name: ${name}
name_add_mac_suffix: false
# name: ${device_name}
# name_add_mac_suffix: true
project:
name: jimmy.easy_skyfandc
version: "0.2"
on_boot: #Setup temperature reading so you don't get a random reading come through at startup
priority: -100
then:
- switch.turn_on: led
- delay: 2s
- switch.turn_off: led
api:
encryption:
key: oy7yLm88W7W3i5b35Dcw4eiDnyjbK2u0zwATzjkAhGc=
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.20.51 #your_device_ip_here
gateway: 192.168.20.1 #your_gateway_here
subnet: 255.255.255.0
ap:
password: ""
packages:
# skyfan.tuya_fan: github://jeggleston1981/skyfandc/tuya_fan.yaml
# skyfan.tuya_light: github://jeggleston1981/skyfandc/tuya_light.yaml
skyfan.sensor_ntc: github://jeggleston1981/skyfandc/sensor_ntc.yaml
skyfan.sensor_tmp117: github://jeggleston1981/skyfandc/sensor_tmp117.yaml
skyfan.sensor_power_fan: github://jeggleston1981/skyfandc/sensor_power_fan.yaml
skyfan.sensor_power_light: github://jeggleston1981/skyfandc/sensor_power_light.yaml
esp8266:
board: d1_mini
#web_server:
# port: 80
#Dashboard import if you want to adopt the device on your esphome dashboard
dashboard_import:
package_import_url: github://jeggleston1981/skyfandc/micro_skyfan2.yaml
# Logger not using the serial port as tuya needs it
logger:
baud_rate: 0
# Version 0.2 has an i2c JST SH 4Pin Plug and uses the following pins
# Version 0.1 did use pin 4 as the power pin for the NTC
i2c:
sda: 4
scl: 5
scan: true
ota:
- platform: esphome
captive_portal:
uart:
rx_pin: GPIO3
tx_pin: GPIO1
baud_rate: 9600
light:
- id: skyfan_light
platform: tuya
name: ${light_name}
switch_datapoint: 15
dimmer_datapoint: 16
min_value: 0
max_value: 5
restore_mode: RESTORE_DEFAULT_OFF
disabled_by_default: false
fan:
- id: skyfan
platform: speed
output: skyfan_speed
direction_output: skyfan_direction
name: ${fan_name}
restore_mode: RESTORE_DEFAULT_OFF
disabled_by_default: false
speed_count: 6
output:
# When the fan speed is changed by the fan entity in Home Assistant, update
# the tuyamcu datapoints that control the fan motor.
- id: skyfan_speed
platform: template
type: float
write_action:
then:
- if:
condition:
- switch.is_on: update_fan
then:
- switch.turn_off: update_fan
else:
- logger.log:
format: "skyfan_speed is %1f"
args: [ 'state' ]
- select.set_index:
id: datapoint_direction
index: !lambda |-
return (id(skyfan).direction != FanDirection::FORWARD ? 1 : 0);
- if:
condition:
lambda: 'return state < 0.1 ;'
then:
- switch.turn_off: datapoint_onoff
else:
- switch.turn_on: datapoint_onoff
- if:
condition:
lambda: 'return (state < 0.3);'
then:
- select.set_index:
id: datapoint_mode
index: 0
- number.set:
id: datapoint_speed
value: 1
else:
- if:
condition:
lambda: 'return (state < 0.4);'
then:
- select.set_index:
id: datapoint_mode
index: 1
else:
- select.set_index:
id: datapoint_mode
index: 0
- if:
condition:
lambda: 'return (state < 0.6);'
then:
- number.set:
id: datapoint_speed
value: 2
else:
- if:
condition:
lambda: 'return (state < 0.8);'
then:
- number.set:
id: datapoint_speed
value: 3
else:
- if:
condition:
lambda: 'return (state < 0.9);'
then:
- number.set:
id: datapoint_speed
value: 4
else:
- number.set:
id: datapoint_speed
value: 5
- id: skyfan_direction
platform: template
type: binary
write_action: []
tuya:
id: tuyamcu
on_datapoint_update:
- sensor_datapoint: 1
datapoint_type: bool
then:
- switch.turn_on: update_fan
- sensor_datapoint: 2
datapoint_type: enum
then:
- switch.turn_on: update_fan
- sensor_datapoint: 3
datapoint_type: int
then:
- switch.turn_on: update_fan
- sensor_datapoint: 8
datapoint_type: enum
then:
- switch.turn_on: update_fan
- sensor_datapoint: 22
datapoint_type: enum
then: []
switch:
- platform: gpio
pin:
number: 2
inverted: true
id: led
# A datapoint has changed in tuyamcu. Update the fan entity in Home Assistant
# to be consistent with the new datapoint values.
- id: update_fan
platform: template
optimistic: true
turn_on_action:
then:
- delay: 200ms
- if:
condition:
- switch.is_on: datapoint_onoff
then:
- if:
condition:
- lambda: 'return ( id(datapoint_mode).active_index() == 1 );'
then:
- logger.log: "update_fan ECO therefore set speed 2"
- fan.turn_on:
id: skyfan
speed: '2'
direction: !lambda |-
bool val = ( id(datapoint_direction).active_index() != 0 );
return val ? FanDirection::REVERSE : FanDirection::FORWARD;
else:
- if:
condition:
- lambda: 'return ( id(datapoint_speed).state == 1 );'
then:
- logger.log: "update_fan Set speed 1"
- fan.turn_on:
id: skyfan
speed: '1'
direction: !lambda |-
bool val = ( id(datapoint_direction).active_index() != 0 );
return val ? FanDirection::REVERSE : FanDirection::FORWARD;
else:
- logger.log: "update_fan Set speed plus 1"
- fan.turn_on:
id: skyfan
speed: !lambda |-
return (id(datapoint_speed).state + 1);
direction: !lambda |-
bool val = ( id(datapoint_direction).active_index() != 0 );
return val ? FanDirection::REVERSE : FanDirection::FORWARD;
else:
- logger.log: "update_fan Turn off"
- fan.turn_off:
id: skyfan
- id: datapoint_onoff
platform: tuya
tuya_id: tuyamcu
name: ${fan_name} Switch
switch_datapoint: 1
internal: true
- platform: restart
name: Restart
entity_category: diagnostic
select:
- platform: "tuya"
name: ${light_color}
enum_datapoint: 19
optimistic: true
options:
0: Froid
1: Neutre
2: Chaud
- id: datapoint_mode
platform: tuya
tuya_id: tuyamcu
name: ${fan_name} Mode
enum_datapoint: 2
options:
0: Normal
1: Economie
2: Sommeil
disabled_by_default: false
- id: datapoint_direction
platform: tuya
tuya_id: tuyamcu
name: ${fan_name} Direction
enum_datapoint: 8
options:
0: FORWARD
1: REVERSE
internal: true
- id: datapoint_timer
platform: tuya
tuya_id: tuyamcu
name: ${fan_name} Timer
enum_datapoint: 22
options:
0: Désactivé
1: 1 heure
2: 2 heures
3: 3 heures
4: 4 heures
5: 5 heures
6: 6 heures
7: 7 heures
8: 8 heures
9: 9 heures
10: 10 heures
11: 11 heures
12: 12 heures
disabled_by_default: false
number:
- id: datapoint_speed
platform: tuya
tuya_id: tuyamcu
name: ${fan_name} Speed
number_datapoint: 3
min_value: 0
max_value: 5
step: 1
internal: true
# Statut de l'ESP
binary_sensor:
- platform: status
name: "Statut"
entity_category: diagnostic
sensor:
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "Signal dB"
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "Signal &"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: " %"
entity_category: "diagnostic"
device_class: ""
- platform: uptime
name: Uptime\config
disabled_by_default: false
force_update: false
unit_of_measurement: s
icon: mdi:timer-outline
accuracy_decimals: 0
device_class: duration
state_class: total_increasing
entity_category: diagnostic
update_interval: 60s
text_sensor:
- platform: wifi_info
ip_address:
name: IP
- platform: version
name: Version
hide_timestamp: true
disabled_by_default: false
icon: mdi:new-box
entity_category: diagnostic
Hello,
When the esp device becomes unavailable the light turns on. Is there a way to disable this behaviour.