My sensors are split out into a sensors.yaml file with a declaration in my config.yaml like:
sensor: !include sensors.yaml
So for the template sensors in that sensors.yaml file, a typical entry looks like:
- platform: template
sensors:
some_sensor:
friendly_name: ‘Some Sensor’
unit_of_measurement: ‘DemiNanoKiloTons’
value_template: “{{ (states(‘sensor.whatever’) | round(0)) }}”
Etc
I’m trying to add a sensor that simply takes the value of another sensor once daily, the example given in the documentation is like:
Example configuration entry
template:
- trigger:
Keep track how many days have past since a date
- name: “Not smoking”
state: ‘{{ ( ( as_timestamp(now()) - as_timestamp(strptime(“06.07.2018”, “%d.%m.%Y”)) ) / 86400 ) | round(default=0) }}’
unit_of_measurement: “Days”
- name: “Not smoking”
I’ve tried a bunch of stuff, but I keep getting syntax errors when I config check it, I am guessing perhaps I have to define the trigger BEFORE the sensor: definition, and that therefore I’d have to split this out into a separate file because my config.yaml has “sensor:” then the include, so I can’t define the trigger first as everything in sensors.yaml is a "sensor: " entry as a result of the way I’ve structured my config.
Can I just confirm I have that right? Does what I’ve said seem sane, and can anyone tell me any other way I could do it to keep everything in the sensors.yaml file (without having to rewrite/restructure that file) for config brevity/neatness - is there any possible way to define the “trigger:” AFTER a “sensor:” definition has already begun as my config structure seems to require?