Every night @ 0001 I query the energy total from the DSB09104 and save it to a file using an automation/script/shell command. I then create a file sensor that pulls this energy reading from the file and maintains the exact reading until the next day’s automation/script/shell command overwrites the file. This total is subtracted from another template sensor that updates the current reading according to the DSB09104’s 30-second (or whatever is set as the interval) posts. I also created a current power sensor, good for situational awareness if you wish to spot check current power usage. The final sensor is a daily cost sensor, taken from multiplying the daily energy use number (kWh) by my energy company’s cost per kilowatt of 12.1 cents (factored in fees and taxes).
- automations.yaml
- id: energybaseline
alias: energybaseline
trigger:
platform: time
at: '00:00:01'
action:
service: script.energybaselinescript
- script.yaml
energybaselinescript:
alias: grab current reading from zwave sensor (midnight)
sequence:
- service: shell_command.energybaselineshell
- shell_command.yaml (NOTE: Remember to change the url to point to your HA instance AND update the api password)
energybaselineshell: "curl -X GET -H 'Content-Type: application/json' 'https://myha.com/api/states/sensor.energymeter_energy?api_password=XXXXXXX' -o /home/ha/.homeassistant/energybaseline.txt"
- sensors.yaml
- platform: file
name: energybaseline
file_path: /home/ha/.homeassistant/energybaseline.txt
value_template: '{{ value_json.state }}'
unit_of_measurement: 'kWh'
- platform: template
sensors:
dailyenergycumulative:
friendly_name: 'Daily Energy Use'
unit_of_measurement: 'kWh'
value_template: '{{ (states.sensor.energymeter_energy.state | float - states.sensor.energybaseline.state | float) | round(2) }}'
- platform: template
sensors:
dailyenergycost:
friendly_name: 'Daily Energy Cost'
unit_of_measurement: '$'
value_template: '{{ (states.sensor.dailyenergycumulative.state | float * 0.121) | round(2) }}'