Skip to content

Instantly share code, notes, and snippets.

@0neday
Last active Mar 26, 2022
Embed
What would you like to do?
homeassisstant pzem-004t power meter
#
utility_meter:
daily_energy:
source: sensor.pzem_004t_energy
name: PZEM-004T Daily Energy
cycle: daily
tariffs:
- peak
- offpeak
monthly_energy:
source: sensor.pzem_004t_energy
name: PZEM-004T Monthly Energy
cycle: monthly
tariffs:
- peak
- offpeak
automation:
trigger:
- platform: time
at: "08:00:00"
- platform: time
at: "21:00:00"
action:
- service: utility_meter.next_tariff
target:
entity_id: utility_meter.daily_energy
- service: utility_meter.next_tariff
target:
entity_id: utility_meter.monthly_energy
template:
- sensors:
today_dianliang:
value_template: >
{{(states("sensor.daily_energy_offpeak") | float + states("sensor.daily_energy_peak") | float ) | round(3)}}
friendly_name: '今日电量'
unit_of_measurement: "kWh"
- sensors:
yesterday_offpeak_dianliang:
value_template: >
{{(state_attr('sensor.daily_energy_offpeak','last_period') | float ) | round(3)}}
friendly_name: '昨日谷电量'
unit_of_measurement: "kWh"
- sensors:
yesterday_peak_dianliang:
value_template: >
{{(state_attr('sensor.daily_energy_peak','last_period') | float ) | round(3)}}
friendly_name: '昨日峰电量'
unit_of_measurement: "kWh"
- sensors:
yesterday_dianliang:
value_template: >
{{(state_attr('sensor.daily_energy_offpeak','last_period') | float + state_attr('sensor.daily_energy_peak','last_period') | float ) | round(3)}}
friendly_name: '昨日总电量'
unit_of_measurement: "kWh"
- sensors:
monthly_dianliang:
value_template: >
{{(states("sensor.monthly_energy_offpeak") | float + states("sensor.monthly_energy_peak") | float ) | round(3)}}
friendly_name: '每月电量'
unit_of_measurement: "kWh"
- sensors:
today_dianfei:
value_template: >
{{(states("sensor.daily_energy_offpeak") | float * 0.3583 + states("sensor.daily_energy_peak") | float * 0.5583 ) | round(4)}}
friendly_name: '今日电费'
unit_of_measurement: "RMB"
- sensors:
yesterday_dianfei:
value_template: >
{{(state_attr('sensor.daily_energy_offpeak','last_period') | float * 0.3583 + state_attr('sensor.daily_energy_peak','last_period') | float * 0.5583 ) | round(4)}}
friendly_name: '昨日电费'
unit_of_measurement: "RMB"
- sensors:
monthly_dianfei:
value_template: >
{{(states("sensor.monthly_energy_offpeak") | float * 0.3583 + states("sensor.monthly_energy_peak") | float * 0.5583 ) | round(4)}}
friendly_name: '每月电费'
unit_of_measurement: "RMB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment