diff --git a/esphome/esp-4chdmxdimmer1 copy.yaml.bak b/esphome/esp-4chdmxdimmer1 copy.yaml.bak new file mode 100644 index 0000000..1830df1 --- /dev/null +++ b/esphome/esp-4chdmxdimmer1 copy.yaml.bak @@ -0,0 +1,233 @@ +########################################################################################## +########################################################################################## +# 4 Channel DMX Mains Dimmer +# This is using an esp8366 (D1 Mini) sensing DMX512 Serial to a 2 channel +# mains lighting contoller (1.2A/Channel) +# +# Contoller: https://www.aliexpress.com/item/32838426377.html +# RS-485 TTL converter: https://www.aliexpress.com/item/1005005737922222.html +# +# V1.0 2025-09-06 First Rev (only tested one module, 2 channels at this stage, and incandescent) +########################################################################################## +# +# NOTES +# - Trialling with an incandescent bulb, 10% writes 26. Max value is 255 so this is 10% +# - With an incandescent, I can't see any light output below about 15% +# - Using GPIO2 as the UART TX on an ESP8266 is handy, as the onboard LED flashes with TX +# - The dimmer needs to be set to DMX mode, and given an ID of 1-999 (not standalone or dynamic) +# - there is no reason you can't run many dimmers off one ESP (limit may be in data speed lags?) +# - The dimmer is pretty smooth, and it remembers values even if no data being transmitted. +# +# System Settings on Dimmer: (onboard buttons M and < held for 2 secs) +# - Set "1 Channel" (d-1) and both channels will output the same levels. Or "2 Channel" (d-2) +# - Set reverse phase dimming/trailing edge (C-R) or Forward/Leading Edge (C-F) +# - Set minimum brightness on the dimmer, from b01-b40. Min is then 5% if b01 +# - Set the 3x 8 Segment display to automatically turn off (Bon/BoF) after a period +# - pull both DE & RE high on the 485 converter to ensure data enabled (or wire to enable_pin) +# +# Other useful references +# - Arduino DMX Controller https://www.youtube.com/watch?v=4PjBBBQB2m4 +# - ESP32 DMX Contoller with ESPixelstick (errors in his wiring diagram) +# https://www.youtube.com/watch?v=GWZ63vsKzT8 +# - ESPHome DMX512 Custom component used here: https://github.com/andyboeh/esphome-dmx512 +# Includes good examples if you are expanding +########################################################################################## +########################################################################################## + +########################################################################################## +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +########################################################################################## +substitutions: + # Device Naming + device_name: "esp-4chdmxdimmer1" + friendly_name: "4 Channel DMX Dimmer 1" + description_comment: "4 Channel Mains Lighting Dimmer using DMX512 protocol" + device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + + # Project Naming + project_name: "Generic ESP8266.D1 Mini" # Project Details + project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + + # Passwords & Secrets + api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names + static_ip_address: !secret esp-4chdmxdimmer1_ip + + # Device Settings + #relay_icon: "mdi:lightbulb-group" + log_level: "DEBUG" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + +######################################################################################### +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +######################################################################################### +# ESPHome +# https://esphome.io/components/esphome.html +######################################################################################### +esphome: + name: "${device_name}" + friendly_name: "${friendly_name}" + comment: "${description_comment}" # Appears on the esphome page in HA + area: "${device_area}" + project: + name: "${project_name}" + version: "${project_version}" + +######################################################################################### +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +######################################################################################### +esp8266: + board: esp01_1m + #early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. + board_flash_mode: dout # Default is dout + restore_from_flash: true # restore some values on reboot + +mdns: + disabled: false # Disabling will make the build file smaller (and it is still available via static IP) + +preferences: + flash_write_interval: 0s + +######################################################################################### +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +############################################# +logger: + level: "${log_level}" #INFO Level suggested, or DEBUG for testing + baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +######################################################################################### +# STATUS LED +# https://esphome.io/components/status_led.html +######################################################################################### +#status_led: +# pin: +# number: GPIO2 +# inverted: yes + +######################################################################################### +# UART COMPONENT +# https://esphome.io/components/uart/ +######################################################################################### +uart: + # Needed for the DMX component. + # This UART talks to the RS485 adaptor + # There is no receiving, it is a one way send + id: uart_bus + baud_rate: 250000 + tx_pin: + number: GPIO2 #ESP8266 + allow_other_uses: true # For ESPHome >= 2023.12.0 + stop_bits: 2 + +########################################################################################## +# LIGHT COMPONENT +# https://esphome.io/components/light/ +########################################################################################## +light: + - platform: monochromatic + name: "Test Lights Chan 1" + output: dmx_1 + id: light_test_1 + default_transition_length: 5s + gamma_correct: 1 + restore_mode: RESTORE_DEFAULT_ON + - platform: monochromatic + name: "Test Lights Chan 2" + output: dmx_2 + id: light_test_2 + default_transition_length: 5s + gamma_correct: 1 + restore_mode: RESTORE_DEFAULT_ON + - platform: monochromatic + name: "Test Lights Chan 3" + output: dmx_3 + id: light_test_3 + default_transition_length: 5s + gamma_correct: 1 + restore_mode: RESTORE_DEFAULT_ON + - platform: monochromatic + name: "Test Lights Chan 4" + output: dmx_4 + id: light_test_4 + default_transition_length: 5s + gamma_correct: 1 + restore_mode: RESTORE_DEFAULT_ON + +########################################################################################## +# SENSOR COMPONENT +# https://esphome.io/components/sensor/ +########################################################################################## + + +########################################################################################## +# CUSTOM COMPONENT DMX512 +# https://github.com/andyboeh/esphome-dmx512 +########################################################################################## +external_components: + - source: github://andyboeh/esphome-dmx512 + +dmx512: + id: dmx + uart_id: uart_bus + #enable_pin: GPIOXX (Optional, I've wire them to be always active) + tx_pin: + number: GPIO2 + allow_other_uses: true # For ESPHome >= 2023.12.0 + uart_num: 1 + +########################################################################################## +# OUTPUT COMPONENT +# https://esphome.io/components/output/ledc.html +########################################################################################## +output: + - platform: dmx512 + channel: 1 # The ID we set the device to + universe: dmx # The ID of the DMX512 Component + id: dmx_1 + - platform: dmx512 + channel: 2 # The ID we set the device to + universe: dmx # The ID of the DMX512 Component + id: dmx_2 + - platform: dmx512 + channel: 3 # The ID we set the device to + universe: dmx # The ID of the DMX512 Component + id: dmx_3 + - platform: dmx512 + channel: 4 # The ID we set the device to + universe: dmx # The ID of the DMX512 Component + id: dmx_4 + diff --git a/esphome/esp-4chdmxdimmer1.yaml b/esphome/esp-4chdmxdimmer1.yaml new file mode 100644 index 0000000..57bc927 --- /dev/null +++ b/esphome/esp-4chdmxdimmer1.yaml @@ -0,0 +1,347 @@ +########################################################################################## +########################################################################################## +# 4 Channel DMX Mains Dimmer +# This is using an esp8366 (D1 Mini) sensing DMX512 Serial to a 2 channel +# mains lighting contoller (1.2A/Channel) +# +# Contoller: https://www.aliexpress.com/item/32838426377.html +# RS-485 TTL converter: https://www.aliexpress.com/item/1005005737922222.html +# +# V1.0 2025-09-06 First Rev (only tested one module, 2 channels at this stage, and incandescent) +########################################################################################## +# +# NOTES +# ------ +# - Trialling with an incandescent bulb, 10% writes 26. Max value is 255 so this is 10% +# - With an incandescent, I can't see any light output below about 15% +# - Using GPIO2 as the UART TX on an ESP8266 is handy, as the onboard LED flashes with TX +# - The dimmer needs to be set to DMX mode, and given an ID of 1-999 (not standalone or dynamic) +# - there is no reason you can't run many dimmers off one ESP (limit may be in data speed lags?) +# - The dimmer is pretty smooth, and it remembers values even if no data being transmitted. +# +# System Settings on Dimmer: (onboard buttons M and < held for 2 secs) +# ------ +# - Set "1 Channel" (d-1) and both channels will output the same levels. Or "2 Channel" (d-2) +# - Set reverse phase dimming/trailing edge (C-R) or Forward/Leading Edge (C-F) +# - Set minimum brightness on the dimmer, from b01-b40. Min is then 5% if b01 +# - Set the 3x 8 Segment display to automatically turn off (Bon/BoF) after a period +# - pull both DE & RE high on the 485 converter to ensure data enabled (or wire to enable_pin) +# +# MAX485 Module (You could also use a MAX3485 which is 3.3V) +# ------ +# MAX485 VCC -> ESP +5V +# MAX485 GND -> ESP GND +# MAX485 DE -> ESP +5V +# MAX485 RE -> Has a pullup so can leave unconnected, (or +5V)or an designated enable_pin +# MAX485 DI -> ESP32 GPIO5 or ESP8266 GPIO2 +# MAX485 A -> XLR 3 (DMX +) +# MAX485 B -> XLR 2 (DMX -) +# MAX485 GND -> XLR 1 (DMX GND) +# +# Other useful references +# ------ +# - Arduino DMX Controller https://www.youtube.com/watch?v=4PjBBBQB2m4 +# - ESP32 DMX Contoller with ESPixelstick (errors in his wiring diagram) +# https://www.youtube.com/watch?v=GWZ63vsKzT8 +# - ESPHome DMX512 Custom component used here: https://github.com/andyboeh/esphome-dmx512 +# Includes good examples if you are expanding +########################################################################################## +########################################################################################## + +########################################################################################## +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +########################################################################################## +substitutions: + # Device Naming + device_name: "esp-4chdmxdimmer1" + friendly_name: "4 Channel DMX Dimmer 1" + description_comment: "4 Channel Mains Lighting Dimmer using DMX512 protocol" + device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + + # Project Naming + project_name: "Generic ESP8266.D1 Mini" # Project Details + project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + + # Passwords & Secrets + api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names + static_ip_address: !secret esp-4chdmxdimmer1_ip + + # Device Settings + #relay_icon: "mdi:lightbulb-group" + log_level: "DEBUG" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + +######################################################################################### +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +######################################################################################### +# ESPHome +# https://esphome.io/components/esphome.html +######################################################################################### +esphome: + name: "${device_name}" + friendly_name: "${friendly_name}" + comment: "${description_comment}" # Appears on the esphome page in HA + area: "${device_area}" + project: + name: "${project_name}" + version: "${project_version}" + on_boot: + priority: -100 + then: + - lambda: |- + id(dmx_ch1_sensor).publish_state(0); + id(dmx_ch2_sensor).publish_state(0); + id(dmx_ch3_sensor).publish_state(0); + id(dmx_ch4_sensor).publish_state(0); + +######################################################################################### +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +######################################################################################### +esp8266: + board: esp01_1m + #early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. + board_flash_mode: dout # Default is dout + restore_from_flash: true # restore some values on reboot + +mdns: + disabled: false # Disabling will make the build file smaller (and it is still available via static IP) + +preferences: + flash_write_interval: 0s + +######################################################################################### +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +############################################# +logger: + level: "${log_level}" #INFO Level suggested, or DEBUG for testing + baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +######################################################################################### +# STATUS LED +# https://esphome.io/components/status_led.html +######################################################################################### +#status_led: +# pin: +# number: GPIO2 +# inverted: yes + +######################################################################################### +# UART COMPONENT +# https://esphome.io/components/uart/ +######################################################################################### +uart: + # Needed for the DMX component. + # This UART talks to the RS485 adaptor + # There is no receiving, it is a one way send + id: uart_bus + baud_rate: 250000 + tx_pin: + number: GPIO2 #ESP8266 + allow_other_uses: true # For ESPHome >= 2023.12.0 + stop_bits: 2 + +########################################################################################## +# LIGHT COMPONENT +# https://esphome.io/components/light/ +########################################################################################## +light: + - platform: monochromatic + name: "Test Lights Chan 1" + output: dmx_1 + id: light_test_1 + default_transition_length: 5s + gamma_correct: 1 + restore_mode: RESTORE_DEFAULT_ON + - platform: monochromatic + name: "Test Lights Chan 2" + output: dmx_2 + id: light_test_2 + default_transition_length: 5s + gamma_correct: 1 + restore_mode: RESTORE_DEFAULT_ON + - platform: monochromatic + name: "Test Lights Chan 3" + output: dmx_3 + id: light_test_3 + default_transition_length: 5s + gamma_correct: 1 + restore_mode: RESTORE_DEFAULT_ON + - platform: monochromatic + name: "Test Lights Chan 4" + output: dmx_4 + id: light_test_4 + default_transition_length: 5s + gamma_correct: 1 + restore_mode: RESTORE_DEFAULT_ON + +########################################################################################## +# SENSOR COMPONENT +# https://esphome.io/components/sensor/ +########################################################################################## +sensor: + # Expose each DMX channel's current output level as 0..255 integers (post-gamma) + - platform: template + id: dmx_ch1_sensor + name: "DMX Ch 1 Output (0-255)" + icon: mdi:counter + #entity_category: diagnostic + accuracy_decimals: 0 + update_interval: never + filters: + - round: 0 + - clamp: + min_value: 0 + max_value: 255 + + - platform: template + id: dmx_ch2_sensor + name: "DMX Ch 2 Output (0-255)" + icon: mdi:counter + #entity_category: diagnostic + accuracy_decimals: 0 + update_interval: never + filters: + - round: 0 + - clamp: + min_value: 0 + max_value: 255 + + - platform: template + id: dmx_ch3_sensor + name: "DMX Ch 3 Output (0-255)" + icon: mdi:counter + #entity_category: diagnostic + accuracy_decimals: 0 + update_interval: never + filters: + - round: 0 + - clamp: + min_value: 0 + max_value: 255 + + - platform: template + id: dmx_ch4_sensor + name: "DMX Ch 4 Output (0-255)" + icon: mdi:counter + #entity_category: diagnostic + accuracy_decimals: 0 + update_interval: never + filters: + - round: 0 + - clamp: + min_value: 0 + max_value: 255 + +########################################################################################## +# CUSTOM COMPONENT DMX512 +# https://github.com/andyboeh/esphome-dmx512 +########################################################################################## +external_components: + - source: github://andyboeh/esphome-dmx512 + +dmx512: + id: dmx + uart_id: uart_bus + #enable_pin: GPIOXX (Optional, I've wire them to be always active) + tx_pin: + number: GPIO2 + allow_other_uses: true # For ESPHome >= 2023.12.0 + uart_num: 1 + #periodic_update: true # optional. Some dimmers may turn off without regular updates. + #force_full_frames: false # optional. If true the 513 byte is always sent + #custom_break_len: 92 # optional. Break Length. Default is 92uS + #custom_mab_len: 12 # optional. Mark after Break Length. Default is 12mS + #update_interval: 500 # optional. Custom update interval. Default is 500mS + +########################################################################################## +# OUTPUT COMPONENT +# https://esphome.io/components/output/ledc.html +########################################################################################## +output: + # Raw DMX slots (these are the actual DMX universes/slots) + - platform: dmx512 + channel: 1 # The ID we set the device to + universe: dmx # The ID of the DMX512 Component + id: dmx_1_raw + - platform: dmx512 + channel: 2 # The ID we set the device to + universe: dmx # The ID of the DMX512 Component + id: dmx_2_raw + - platform: dmx512 + channel: 3 # The ID we set the device to + universe: dmx # The ID of the DMX512 Component + id: dmx_3_raw + - platform: dmx512 + channel: 4 # The ID we set the device to + universe: dmx # The ID of the DMX512 Component + id: dmx_4_raw + + # Wrapped outputs: publish exact 0..255 to sensors, then forward float to raw DMX + - platform: template + id: dmx_1 + type: float + write_action: + - lambda: |- + id(dmx_ch1_sensor).publish_state(state * 255.0f); + id(dmx_1_raw).set_level(state); + + - platform: template + id: dmx_2 + type: float + write_action: + - lambda: |- + id(dmx_ch2_sensor).publish_state(state * 255.0f); + id(dmx_2_raw).set_level(state); + + - platform: template + id: dmx_3 + type: float + write_action: + - lambda: |- + id(dmx_ch3_sensor).publish_state(state * 255.0f); + id(dmx_3_raw).set_level(state); + + - platform: template + id: dmx_4 + type: float + write_action: + - lambda: |- + id(dmx_ch4_sensor).publish_state(state * 255.0f); + id(dmx_4_raw).set_level(state); + + diff --git a/esphome/esp-centralstairs-bottom.yaml b/esphome/esp-centralstairs-bottom.yaml index d1ad394..5b3af7f 100644 --- a/esphome/esp-centralstairs-bottom.yaml +++ b/esphome/esp-centralstairs-bottom.yaml @@ -120,7 +120,7 @@ esp8266: ######################################################################################### # ESPHome Logging Enable # https://esphome.io/components/logger.html -############################################# +######################################################################################### logger: level: "${log_level}" #INFO Level suggested, or DEBUG for testing #baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) diff --git a/esphome/esp-loungemoesdimmer2.yaml b/esphome/esp-loungemoesdimmer2.yaml new file mode 100644 index 0000000..c884dc3 --- /dev/null +++ b/esphome/esp-loungemoesdimmer2.yaml @@ -0,0 +1,195 @@ +########################################################################################## +########################################################################################## +# Moes Mains Dimmer +# Mains dimmer 150W single channel - Moes Wi-Fi Dimmer Module +# Module swapped to a ESP-02S module (from a Tuya WB2S) +# +# V1.0 2025-09-05 First Rev +########################################################################################## +# +# NOTES RE TUYA COMMS FOR THIS MODULE +# - Toggle DP1 (switch) to 1 or 0 for ON or OFF. The dimmer's MCU does the smooth ramp itself over a few seconds. +# - We set DP2 (brightness) on a 0-1000 scale; this is the actual brightness level your firmware uses. +# - We read DP2 back as a sensor (and also show a % view) so we can see the live target the MCU is using. +# - DP3 is exposed only as an optional minimum-brightness limit; not touched during normal dimming unless you tune the low end. +# - It appears that 11 is the lowest DP3 raw value. Brightness of 1% sets this, and 2% ramps it to 19. +# - 50% brightness is 501, so it is pretty linear (you can't set Gamma, see below - I guess you could script it though) +# - DP4 (mode) exists but left alone (unless you want to experiment with load type/behavior). I can't see it do anything. Disabled by default in HA. +# - gamma_correct supposedly remaps the HA slider (no Tuya traffic) BUT it must be set to 1 or weird behaviour (keeps ramping to 0) +# - setting logs to DEBUG will show what is happening with Tuya commands +# +########################################################################################## +########################################################################################## + +########################################################################################## +# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS +# If NOT using a secrets file, just replace these with the passwords etc (in quotes) +########################################################################################## +substitutions: + # Device Naming + device_name: "esp-loungemoesdimmer2" + friendly_name: "Lounge Lighting Moes Dimmer 2" + description_comment: "tba" + device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. + + # Project Naming + project_name: "Generic ESP8266.ESP-02S" # Project Details + project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version + + # Passwords & Secrets + api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names + static_ip_address: !secret esp-loungemoesdimmer2_ip + + # Device Settings + #relay_icon: "mdi:lightbulb-group" + log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE + update_interval: "60s" # update time for for general sensors etc + +######################################################################################### +# PACKAGES: Included Common Packages +# https://esphome.io/components/packages.html +########################################################################################## +# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors +########################################################################################## +packages: + common_wifi: !include + file: common/network_common.yaml + vars: + local_device_name: "${device_name}" + local_static_ip_address: "${static_ip_address}" + local_ota_pass: "${ota_pass}" + common_api: !include + file: common/api_common.yaml + vars: + local_api_key: "${api_key}" + #common_webportal: !include + # file: common/webportal_common.yaml + common_mqtt: !include + file: common/mqtt_common.yaml + vars: + local_device_name: "${device_name}" + common_sntp: !include + file: common/sntp_common.yaml + common_general_sensors: !include + file: common/sensors_common.yaml + vars: + local_friendly_name: "${friendly_name}" + local_update_interval: "${update_interval}" + +######################################################################################### +# ESPHome +# https://esphome.io/components/esphome.html +######################################################################################### +esphome: + name: "${device_name}" + friendly_name: "${friendly_name}" + comment: "${description_comment}" # Appears on the esphome page in HA + area: "${device_area}" + project: + name: "${project_name}" + version: "${project_version}" + +######################################################################################### +# ESP Platform and Framework +# https://esphome.io/components/esp32.html +######################################################################################### +esp8266: + board: esp01_1m + #early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. + board_flash_mode: dout # Default is dout + +######################################################################################### +# ESPHome Logging Enable +# https://esphome.io/components/logger.html +############################################# +logger: + level: "${log_level}" #INFO Level suggested, or DEBUG for testing + baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) + #esp8266_store_log_strings_in_flash: false + #tx_buffer_size: 64 + +######################################################################################### +# STATUS LED +# https://esphome.io/components/status_led.html +######################################################################################### +status_led: + pin: + number: GPIO2 + inverted: yes + +######################################################################################### +# UART COMPONENT +# https://esphome.io/components/uart/ +######################################################################################### +uart: + # Needed for the Tuya component. + # This UART talks to the coprocessing tuya chip + tx_pin: GPIO1 + rx_pin: GPIO3 + baud_rate: 9600 + +######################################################################################### +# TUYA MCU COMPONENT +# https://esphome.io/components/tuya/ +######################################################################################### +tuya: + # logger baud_rate must be 0 + id: tuyamcu + +########################################################################################## +# LIGHT COMPONENT +# https://esphome.io/components/light/ +########################################################################################## +light: + - platform: tuya + name: "Lounge Lighting Moes Dimmer 1" + switch_datapoint: 1 # ON/OFF + dimmer_datapoint: 2 # <-- CHANGED: brightness is DP2 on your unit + #min_value_datapoint: 3 # optional; comment this out if it misbehaves + min_value: 0 + max_value: 1000 + gamma_correct: 1.0 + default_transition_length: 0s + +########################################################################################## +# SENSOR COMPONENT +# https://esphome.io/components/sensor/ +########################################################################################## +sensor: + # The raw value sent over the UART + # Listed as a dignostic, so will appear with the other diags in HA + - platform: tuya + id: dp2_brightness_raw + name: "Brightness (DP2 raw)" + sensor_datapoint: 2 + entity_category: diagnostic + # Raw value as a percentage of max + - platform: template + name: "Brightness (%)" + unit_of_measurement: "%" + accuracy_decimals: 0 + update_interval: 2s + lambda: |- + if (isnan(id(dp2_brightness_raw).state)) return NAN; + return (id(dp2_brightness_raw).state / 1000.0f) * 100.0f; + +########################################################################################## +# SELECT COMPONENT +# https://esphome.io/components/select/ +########################################################################################## +select: + # Experimental + - platform: tuya + id: dp4_mode + name: "DP4 Mode (experiment)" + enum_datapoint: 4 + options: + 0: "Mode 0" + 1: "Mode 1" + 2: "Mode 2" + 3: "Mode 3" + 4: "Mode 4" + 255: "Default/Unknown" + entity_category: config + disabled_by_default: true \ No newline at end of file