I configured this device with localTuya as a switch with attributes for current (DP18) and voltage (DP20) and added power (DP19) as a power type sensor and “add electricity” (DP17) as a energy type sensor.
Then I defined an separate sensor to sum-up the “add electricity” sensor as blow. It kind of works, but it is not completely accurate as it sometimes misses an addition when the “add electricity” updates with the same value as before. Not sure what to do next.
Also, I don’t see the localTuya entities for this device listed under HA\Developer Tools\Statistics. When the entities are not included in the recorder integration, where does it store its data?
configuration.yaml:
input_number:
pp1_previous_add_value:
name: PP1 Add Value
min: 0
max: 100000
mode: box
pp1_energy_value:
name: PP1 Energy Value
min: 0
max: 10000000
mode: box
sensor:
- platform: template
sensors:
pp1_energy:
friendly_name: "PP1 Energy"
unique_id: pp1_energy
unit_of_measurement: "Wh"
device_class: energy
value_template: >
{{ states('input_number.pp1_energy_value') | int(0) }}
automations.yaml:
alias: PP1 Energy
description: ""
triggers:
- minutes: /5
trigger: time_pattern
conditions:
- condition: template
value_template: >-
{{ states('sensor.pp1_add_electricity') | int(0) !=
states('input_number.pp1_previous_add_value') | int(0) }}
actions:
- data:
entity_id: input_number.pp1_previous_add_value
value: "{{ states('sensor.pp1_add_electricity') | int(0) }}"
action: input_number.set_value
- data:
entity_id: input_number.pp1_energy_value
value: >-
{{ states('sensor.pp1_energy') | int +
states('sensor.pp1_add_electricity') | int }}
action: input_number.set_value
mode: single