Skip to content

Instantly share code, notes, and snippets.

@billchurch
Created July 26, 2024 19:58
Show Gist options
  • Save billchurch/ddca6f6364a0ec1b9260388f82d1f5a8 to your computer and use it in GitHub Desktop.
Save billchurch/ddca6f6364a0ec1b9260388f82d1f5a8 to your computer and use it in GitHub Desktop.
tuya fan with esphome and home assistant
substitutions:
device_name: living-fan
device_description: Living Room Ceiling Fan
friendly_name: Living Room Fan
esphome:
name: ${device_name}
comment: ${device_description}
platform: ESP8266
board: esp01_1m
# Disable logging on serial as it is used by the TuyaMCU
logger:
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: !secret esphome_key
reboot_timeout: 0s
ota:
platform: esphome
wifi:
ssid: !secret wifissid
password: !secret wifipass
fast_connect: off #we only have one WiFi AP so just use the first one that matches
# domain: !secret domain
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${device_name} Fallback Hotspot"
password: !secret wifipass
captive_portal:
web_server:
port: 80
time:
- platform: homeassistant
id: time_homeassistant
on_time_sync:
- component.update: sensor_uptime_timestamp
uart:
tx_pin: GPIO01
rx_pin: GPIO03
baud_rate: 9600
# debug:
# sequence:
# - lambda: UARTDebug::log_hex(direction, bytes, ',');
sensor:
- platform: uptime
id: sensor_uptime
- platform: template
id: sensor_uptime_timestamp
name: "${friendly_name} Uptime"
device_class: "timestamp"
accuracy_decimals: 0
update_interval: never
lambda: |-
static float timestamp = (
id(time_homeassistant).utcnow().timestamp - id(sensor_uptime).state
);
return timestamp;
- platform: wifi_signal
name: ${friendly_name} Signal
update_interval: 60s
tuya:
fan:
- platform: "tuya"
name: "Fan"
switch_datapoint: 1
speed_datapoint: 3
direction_datapoint: 103
speed_count: 10
light:
- platform: "tuya"
id: tuya_light_warm
internal: True
dimmer_datapoint: 10
switch_datapoint: 9
min_value: 100
max_value: 1000
- platform: "tuya"
internal: True
id: tuya_light_cold
dimmer_datapoint: 102
switch_datapoint: 101
min_value: 100
max_value: 1000
- platform: cwww
name: "Light"
id: cwww_light
cold_white: cold_light
warm_white: warm_light
cold_white_color_temperature: 4000 K
warm_white_color_temperature: 370 mireds # ~ 2700K, avoid mireds rounding errors
default_transition_length: 0s
output:
- platform: template
id: warm_light
type: float
write_action:
- light.control:
id: tuya_light_warm
brightness: !lambda return state;
state: !lambda return state > 0;
- platform: template
id: cold_light
type: float
write_action:
- light.control:
id: tuya_light_cold
brightness: !lambda return state;
state: !lambda return state > 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment