Calcular o consumo a pagar no ESPhome

Com base na dúvida que vi em https://forum.cpha.pt/t/duvida-template-consumo-tomada/2154 eu gostaria de realizar o cálculo do consumo. Pelo que encontrei, teria que aplicar utilizando o lambda, mas não consegui chegar a nenhum resultado. Não entendi e não aprendi a aplica o cálculo usando o código value_template: "{{ ( float(states.sensor.tomada_quarto_consumo_diario.state) * float(states.input_text.valor_kwh.state) ) | round(2) }}"
Obs.: veja que uso um input_text.valor_kwh para informar o valor da minha tarifa.

sensor:
tomada_quarto_energia_gasta_dia:
friendly_name: “Gasto no dia Tomada Quarto”
icon_template: mdi:cash-usd-outline
unit_of_measurement: ‘R$’
value_template: “{{ ( float(states.sensor.tomada_quarto_consumo_diario.state) * float(states.input_text.text_valor_kwh.state) ) | round(2) }}”

Segue o código referente ao ESPhome:

substitutions:
  devicename: esp_ac_quarto
  friendly_name: AC Quarto
  ip_address: 192.168.1.206

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

wifi:
  ssid: !secret wifi_iot_ssid
  password: !secret wifi_iot_psk
  manual_ip:
    static_ip: $ip_address
    gateway: 192.168.1.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: $friendly_name Hotspot
    password: !secret ap_psk

captive_portal:

# Enable logging
logger:
  baud_rate: 0 # Disable logging over USB

# Enable Home Assistant API
api:

ota:
  password: !secret ota_psk

web_server:
  port: 80

uart:
  rx_pin: RX
  baud_rate: 4800

time:
  - platform: homeassistant
    id: homeassistant_time
  - platform: homeassistant
    on_time:
      - seconds: 50
        minutes: 59
        hours: 23
        then:
           - sensor.template.publish:
               id: template_yesterday
               state: !lambda return id(total_daily).state ;

switch:
  - platform: template
    name: $friendly_name Botão
    optimistic: true
    id: fakebutton
    turn_on_action:
    - switch.turn_on: relay
    - light.turn_on: led
    turn_off_action:
    - switch.turn_off: relay
    - light.turn_off: led
  - platform: gpio
    id: relay
    pin: GPIO12

binary_sensor:
  - platform: gpio
    id: button
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      - switch.toggle: fakebutton
  - platform: template
    name: $friendly_name
    filters:
      - delayed_off: 15s
    lambda: |-
      if (isnan(id(power).state)) {
        return {};
      } else if (id(power).state > 2) {
        // Running
        return true;
      } else {
        // Not running
        return false;
      }

output:
  - platform: esp8266_pwm
    id: pow_blue_led
    pin:
      number: GPIO13
      inverted: True

light:
  - platform: monochromatic
    output: pow_blue_led
    id: led

sensor:
  - platform: cse7766
    current:
      name: $friendly_name Corrente
      icon: "mdi:flash-circle"
      unit_of_measurement: "A"
    voltage:
      name: $friendly_name Voltagem
      icon: "mdi:flash-circle"
      unit_of_measurement: "V"
    power:
      name: $friendly_name Consumo
      icon: "mdi:flash-circle"
      unit_of_measurement: "W"
      id: power
      on_value_range:
        - above: 38.0
          then:
            - light.turn_on: led
        - below: 37.0
          then:
            - light.turn_off: led

  - platform: wifi_signal
    name: $friendly_name Sinal WiFi
    update_interval: 60s

  - platform: uptime
    name: $friendly_name UpTime

  - platform: total_daily_energy
    id: total_daily
    name: $friendly_name Total Energia Dia
    power_id: "power"
    filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
    unit_of_measurement: kWh

  - platform: template
    name: $friendly_name Total Energia Ontem
    id: template_yesterday
    accuracy_decimals: 3
    unit_of_measurement: kWh

text_sensor:
  - platform: version
    name: $friendly_name Versão ESP

Copyright © 2017-2020. Todos os direitos reservados
CPHA.pt - info@cpha.pt


FAQ | Termos de Serviço/Regras | Política de Privacidade