substitutions: device_name: "tuyaplug001" friendly_name: "tuya plug 001" comment: "eps-02S, tuya-hack" location: "zolder" api_password: !secret tuya_plug_api ota_password: !secret ota_password wifi_ssid: !secret wifi_ssid wifi_password: !secret wifi_password gateway: !secret ip_gateway subnet: !secret ip_subnet ip: !secret tuya_plug_001_ip pin_relay: GPIO14 pin_button: GPIO1 pin_status: GPIO13 pin_cf: GPIO05 pin_cf1: GPIO04 pin_sel: GPIO12 packages: board: !include boards/esp01.yaml connection: !include common/wifi.yaml device_base: !include common/common.yaml status: !include templates/status.yaml logger: !include templates/nologger.yaml binary_sensor: - platform: gpio pin: number: ${pin_button} mode: input: true pullup: true inverted: true name: "Button" on_press: - switch.toggle: relay switch: # the power relay - platform: gpio id: relay pin: ${pin_relay} name: '${device_name}' restore_mode: RESTORE_DEFAULT_ON # attempt to restore state on start and defaults to OFF if failed icon: mdi:power-socket-de sensor: - platform: hlw8012 model: BL0937 # note that the model must be specified to use special calculation parameters current_resistor: 0.001 # adjust it according to the actual resistor value on board voltage_divider: 2012 # (2008.1K)/998 = 2004, adjust it according to the actual resistor values on board sel_pin: number: ${pin_sel} inverted: true # the logic of BL0937 is opposite from HLW8012 cf_pin: ${pin_cf} cf1_pin: ${pin_cf1} current: name: '${device_name} Current' voltage: name: '${device_name} Voltage' power: name: '${device_name} Power' energy: name: '${device_name} Energy' # convert to kWh filters: - multiply: 0.001 unit_of_measurement: 'kWh' accuracy_decimals: 4 update_interval: 10s change_mode_every: 3