baz123
(Brian)
October 5, 2022, 6:56am
1
I have an incrementing sensor that resets at midnight. I want to be able to determine what the final value was before it reset.
I asked the question - Last total value for total_increasing sensor
I tried an Automation using a trigger of
trigger:
- platform: state
entity_id: sensor.komfovent_heater_consumption_day_kwh
to: '0.0'
but this never fires - if I do it at 0.01 it does fire (and give me 0)
How much X was yesterday is really useful.
petro
(Petro)
October 5, 2022, 10:46am
2
Use a numeric state trigger, and look for below: 0.01.
baz123
(Brian)
October 5, 2022, 11:44am
3
Thanks, I’ll try it tonight, but I still think there is a place for this to be easily created (perhaps a helper) on a per sensor basis.
I’m pulling the value from {{trigger.from_state.state}}
all of which does feel is a bit of a cludge.
baz123
(Brian)
October 6, 2022, 10:48am
4
Thanks, that worked but I think this could be a helper (as it would then create the sensor etc).
petro
(Petro)
October 6, 2022, 11:46am
5
Not sure what you mean. If you want a sensor, you’d make a template sensor. Helpers are store info, so if you made it as a helper, you’d make it as a boolean with an automation. Not really useful IMO when you have a trigger right there that behaves the exact same way.
baz123
(Brian)
October 6, 2022, 1:17pm
6
To make the template sensor, do I not need an automation to trigger it?
petro:
Helpers are store info
Not sure what you mean here.
What I’d like is, on a daily basis, to display how much energy I used yesterday and store that figure for future use.
petro
(Petro)
October 6, 2022, 1:21pm
7
No, template sensors just collect info.
Have you looked at utility meter?
not wanting to take away from your WTH, but you can do that with eg mqtt. create a sensor, and record that sensor. its what I do like this:
script:
publish_sensor_daystart_values:
alias: Publish sensor daystart values
sequence:
- variables:
switches: >
{{expand('switch.shelly_switches')|map(attribute='object_id')|list}}
sensors: >
{{expand('sensor.co2_living','sensor.luchtvochtigheid_living',
'sensor.temperatuur_living')
|map(attribute='object_id')|list}}
- repeat:
count: >
{{switches|count}}
sequence:
- variables:
oid: >
{{switches[repeat.index - 1]}}
# wattage, power sensors
actueel: >
sensor.{{oid}}_actueel
# kWh, energy sensors
totaal: >
sensor.{{oid}}_totaal
- service: mqtt.publish
data:
topic: >
ha_main/sensor/{{oid}}/power_daystart
payload_template: >
{{states(actueel)}}
qos: 2
retain: true
- service: mqtt.publish
data:
topic: >
ha_main/sensor/{{oid}}/energy_daystart
payload_template: >
{{states(totaal)}}
qos: 2
retain: true
- repeat:
count: >
{{sensors|count}}
sequence:
- variables:
oid: >
{{sensors[repeat.index - 1]}}
value: >
sensor.{{oid}}
- service: mqtt.publish
data:
topic: >
ha_main/sensor/co2_monitor_air_quality_detector/{{oid}}_daystart
payload_template: >
{{states(value)}}
qos: 2
retain: true
and automate that:
automation:
- alias: Set daystart sensors
id: set_daystart_sensors
trigger:
platform: time
at: '00:00:01'
action:
- service: script.publish_sensor_daystart_values
the Utilty meters daily sensors are a bit odd to me, (have them on all power meters) aas they seem to increase during the day.,… and not just during day change
baz123
(Brian)
October 6, 2022, 2:24pm
9
The trigger @petro works for me so my automation looks like this;
- alias: daily heater consumption kWh
description: ''
mode: single
trigger:
- platform: numeric_state
entity_id: sensor.consumption_day_kwh
below: 0.01
action:
- service: mqtt.publish
data:
topic: ha/kom_heater_yesterday
retain: true
payload: '{{trigger.from_state.state}}'
It sort of proves my point “WTH is it so difficult to get a figure for how much I used yesterday!” . I suppose the argument could be that this is not about automation .
Perhaps what is needed is a generic accumulation sensor? We have specific ones for energy (and I think water now) why not make it generic?
Features:
Specify period or reset time (D/W/M/Y/30d/1h/24h)
incoming data sensor
units
attribute of last period value
petro
(Petro)
October 6, 2022, 2:28pm
10
The energy ones (utility_meter) work for any entity though. Either way, if you’re put off by that, you can just use the statistics sensor that does similar computations.
baz123
(Brian)
October 6, 2022, 2:32pm
11
Does it assume kWh (I haven’t looked TBH).
The trouble with the statistics sensor (as mentioned in other threads) is you cannot specify the time period it works on. It just does 24h.
It still doesn’t solve the “I want yesterday’s max figure” issue.
petro
(Petro)
October 6, 2022, 2:35pm
12
It doesn’t care. The utility_meter integration was designed for what you want. Here’s a simple config of it
utility_meter:
kom_heater_yesterday:
source: sensor.consumption_day_kwh
cycle: daily
EDIT: Forgot you want yesterdays info.
baz123
(Brian)
October 6, 2022, 2:38pm
13
It would be better to call it a generic accumulator then (as there are plenty of other accumulators rather than utility).
It still does not have the “What was the last figure before reset” - which is where I came in
It could be added as an attribute of the sensor.