hebom
(Christiaan)
October 23, 2022, 10:19am
1
I’m trying to create a sensor that ups it’s value with one every day.
My current config won’t show up in the developer options nor entities.
sensors:
- trigger:
- platform: time
hours: 0
minutes: 0
seconds: 0
sensor:
- name: Levering elektra
unique_id: levering_elektra
unit_of_measurement: 'kWh'
state: "{{ states('sensor.levering_elektra') | int + 1 }}"
The use of this sensor is to add a consumer to the Energy Dashboard with the daily usage fee (based on my monthly fee).
Hellis81
(Hellis81)
October 23, 2022, 10:26am
2
It’s probably better to use a input number which will remember it’s value past a restart.
tom_l
October 23, 2022, 10:36am
3
Template sensors are restored.
Change the trigger to:
template:
- trigger:
- platform: time
at: "00:00:00"
sensor:
- name: Levering elektra
unique_id: levering_elektra
unit_of_measurement: 'kWh'
state: "{{ states('sensor.levering_elektra') | int + 1 }}"
You seem to have used a miss-mash of time and time_pattern triggers. Also it goes under the template
integration. Not “sensors”.
If it resets monthly you could just use the day number.
template:
- sensor:
- name: Levering elektra
unique_id: levering_elektra
unit_of_measurement: 'kWh'
state: "{{ now().day }}"
1 Like
hebom
(Christiaan)
October 23, 2022, 11:11am
4
You’re correct, I’ve used time_pattern for testing, but the sensor isn’t showing up in HA.
I’ve created a template.yaml and made a referal to that file in my configuration.yaml (template: !include includes/template.yaml
), my template.yaml starts with sensor:
(the other sensors in template.yaml work).
For testing I’ve used the following and I hoped it would increment the value of sensor.levering_elektra with one every 10 seconds.
- trigger:
- platform: time_pattern
hours:
minutes:
seconds: /10
sensor:
- name: Levering elektra
unique_id: levering_elektra
unit_of_measurement: 'kWh'
state: "{{ states('sensor.levering_elektra') | int + 1 }}"
tom_l
October 23, 2022, 11:17am
5
Initially your sensor is undefined so the int
filter does not work (there are probably errors about this in your logs). Supplying a default of 0 will fix this.
template:
- trigger:
- platform: time_pattern
hours:
minutes:
seconds: /10
sensor:
- name: Levering elektra
unique_id: levering_elektra
unit_of_measurement: 'kWh'
state: "{{ states('sensor.levering_elektra') | int(0) + 1 }}"
1 Like
This was helpful to a problem I’m trying to solve; however, when I reload my configuration/reboot this reinitializes the sensor to 0 every time.
Is there a way to resolve this?
tom_l
August 31, 2023, 2:15pm
7
Probably better to increment a counter with an automation then.