Código para tomada tuya com medição de consumo

substitutions:
  devicename: tomada-wifi-01
  friendly_name: Tomada wifi 01

esphome:
  name: $devicename
  platform: ESP8266
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "senha ota"

wifi:
  ssid: "nome do wifi"
  password: "senha do wifi"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "nome do hotspot"
    password: "senha do hotspot"

captive_portal:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO03
      mode: INPUT_PULLUP
      inverted: True
    name: ${friendly_name} - Botão
    on_press:
      - switch.toggle: fakebutton
      
sensor:
  - platform: hlw8012
    sel_pin: 12
    cf_pin: 04
    cf1_pin: 05
    update_interval: 1s
    current:
      name: "${friendly_name} - Corrente"
      filters:
        - multiply: 0.001
      accuracy_decimals: 3
      unit_of_measurement: A
      icon: mdi:current-ac
    voltage:
      name: "${friendly_name} - Voltagem"
      unit_of_measurement: V
      icon: mdi:sine-wave
    energy:
      name: "${friendly_name} - Consumo total"
      icon: mdi:flash
      filters:
        - multiply: 0.001
      accuracy_decimals: 3
      unit_of_measurement: kWh
    power:
      id: power
      name: "${friendly_name} - Potência"
      filters:
        - lambda: return x / 100.0;
      unit_of_measurement: W
      
  - platform: total_daily_energy
    name: "${friendly_name} - Consumo diário"
    icon: mdi:flash
    power_id: power
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh
            
  - platform: wifi_signal
    name: ${friendly_name} - Sinal
    update_interval: 60s

switch:
  - platform: template
    name: ${friendly_name} - Relé
    optimistic: true
    id: fakebutton
    turn_on_action:
      - switch.turn_on: relay
      - light.turn_on: led
    turn_off_action:
      - switch.turn_off: relay
      - light.turn_on: led
  - platform: gpio
    id: relay
    pin: GPIO14
    
light:
  - platform: monochromatic
    name: ${friendly_name} - Led azul
    output: led_azul
    id: led
    
output:
  - platform: esp8266_pwm
    id: led_azul
    pin:
      number: GPIO13
      inverted: True
      
time:
  - platform: homeassistant
    id: homeassistant_time
Código para tomada tuya com medição de consumo
300x250
Código para tomada tuya com medição de consumo
Código para tomada tuya com medição de consumo
Código para tomada tuya com medição de consumo
Código para tomada tuya com medição de consumo