Hello I’ll explain my problem and sorry if it’s easier than it seems to me.
I can’t have a smart gas meter so I created one virtually.
I have a sensor that activates when the boiler turns on and, as an approximation, I was able to calculate the average gas consumption in m3 per hour. Creating a template with the gas consumption was easy.
However, I would like to add the gas consumption of the kitchen burners (the boiler obviously doesn’t turn on).
Again as an approximation, I calculated that I consume about 0.2 m3 of gas for cooking per day.
How can I create a sensor that every day, at a specific time (say at 12h) increases by a fixed value?
So even in the consumption graph I would have the consumption in the kitchen at the right time.
Thanks in advance
I think I would create a helper → template → sensor
in that I would make the value something like this
{% set test = now().strftime('%H%M') %}
{{ 2222.222/60 |float if test in ["1607", "1807"] else 0 }}
where 2222.22…/60 is the value you want to add divided appropriately for the time period (1min)
1607… is the time it should be applied, make it “1200” for noon (or i set it so you can have multiple times like “1807” so you can put in more than one point during the day… maybe you cook in the evening as well ? add with a comma remove as needed )
I think you should make it a measurement and relate it to gas and the appropriate units you use for the boiler.
not sure about the graph but i think if you put them stacking it will show the total … but if you want the total I think you would need another sensor that sums all the sensors.
someone probably has a better way. but I think that this would likely get you what you after
Thanks for your help Patrch. I’ll try to implement this template for my purposes. In case of doubt i’ll ask.
I don’t understand the proposed solution. It doesn’t correspond to what the OP is asking in the quoted text at all, as far as I can tell.
If you literally want a sensor that increases by a fixed value every day at a particular time, the best bet is probably a trigger-based sensor:
- trigger:
- platform: time_pattern
# In this exampe, the sensor will increase by fixed_val at noon every day
hours: "12"
action:
- variables:
# fixed_val is the amount by which you want to increase
fixed_val: 1
current_val: " {{ states('ENTITY_ID_HERE') | float(0) }} "
sensor:
# Define your name/unique_id/etc here
- name: "My sensor"
state: " {{ (current_val + fixed_val) | float }}"
Thanks for the idea, instinctively I too had thought of a trigger sensor.
I just have one doubt though:
action:
- variables:
# fixed_val is the amount by which you want to increase
fixed_val: 1
current_val: " {{ states('ENTITY_ID_HERE') | float(0) }} "
It’s not clear to me what kind of entity i have to choose for current_val variable.
I have to create an entity from scratch or an existing entity. I did some tests in developers Tools models and it says:
Undefined Error: current_val is undefined
both if I put an entity ID already created or from scratch…
Thanks in advance
I tested and confirmed the following example works.
- trigger:
- platform: time
at: '12:00:00'
sensor:
- name: Gas Consumption
unique_id: gas_consumption_abc123
state: "{{ this.state | float(0) + 0.2 }}"
device_class: gas
unit_of_measurement: 'm³'
The initial value will be unknown
. It will change to 0.2
the first time it triggers at 12:00:00
. It increments its value by 0.2
every time the trigger fires.
Solved.Thanks to everybody.