Do you have a sensor.time
?
Also that was meant to be a binary_sensor, not a sensor.
If you do change it use states 'on'
and 'off'
, not True
and False
in your automation.
Do you have a sensor.time
?
Also that was meant to be a binary_sensor, not a sensor.
If you do change it use states 'on'
and 'off'
, not True
and False
in your automation.
Ahh, okay, I’ve changed the sensor to a binary and changed the automations aswell!
I do have a sensor.time!
This trigger will be binary_sensor.varm...
now.
- alias: Starta värmefläkt
trigger:
- platform: state
entity_id: sensor.varmeflakt_timer
That’s weird…that didn’t work
The binary sensor didn’t change from off to on based on the values from the input_numbers.
What does this give you in the developer tools / template editor:
start: {{ states('input_number_varmeflakt_start') }}
stop: {{ states('input_number_varmeflakt_stopp') }}
now hour: {{ now().hour }}
time: {{ states('sensor.time') }}
It gives:
start: unknown
stop: unknown
now hour: 19
time: 19:10
But if I change from:
start: {{ states('input_number_varmeflakt_start') }}
stop: {{ states('input_number_varmeflakt_stopp') }}
now hour: {{ now().hour }}
time: {{ states('sensor.time') }}
to:
start: {{ states('input_number.varmeflakt_start') }}
stop: {{ states('input_number.varmeflakt_stopp') }}
now hour: {{ now().hour }}
time: {{ states('sensor.time') }}
I get the following:
start: 0.0
stop: 0.0
now hour: 19
time: 19:10
Which seems more accurate!
But I don’t know if the decimals will mess things up?
Doh. Yeah those should definitely be periods not underscores. Well done.
No the decimal points wont matter for less than / greater than comparisons. They just have to be numbers.
Why are your input numbers both zero though?
Both my sliders where at zero when testing, now, when set, they show up correct numbers!
start: 20.0
stop: 21.0
now hour: 19
time: 19:19
So now I’ll just have to wait and see how it plays out
Okay, so it kinda works, the sensor gets set to “on” at specified hour, but for some reason it doesn’t get set to “off” at the next specified hour…any ideas why?
Can you post the sensor config and automation(s) involved?
See below!
- platform: template
sensors:
varmeflakt_timer:
friendly_name: "Timer"
value_template: >-
{% set update = states('sensor.time') %}
{% set t = now().hour %}
{% set start = states('input_number.varmeflakt_start')|int %}
{% set stop = states('input_number.varmeflakt_stopp')|int %}
{{ start <= t <= stop }}
- alias: Starta värmefläkt
trigger:
- platform: state
entity_id: binary_sensor.varmeflakt_timer
from: 'off'
to: 'on'
action:
- service: switch.turn_on
entity_id: switch.shelly_varmeflakt
- alias: Stäng av värmefläkt
trigger:
- platform: state
entity_id: binary_sensor.varmeflakt_timer
from: 'on'
to: 'off'
action:
- service: switch.turn_off
entity_id: switch.shelly_varmeflakt
Might it be something with this line?
{{ start <= t <= stop }}
Automations work, I’ve tried them both setting the state manually!
No, that looks valid.
Try:
{% set t = now().hour|int %}
Unfortunantly that didn’t help
I know what it is. Try this:
{{ start <= t < stop }}
t equal to your stop hour was keeping the sensor on.
Okay, for some reason when it is supposed to set the state to “off”…it seems to get set to “on”.
See screenshots below…screenshots taken at 18:14!
Yep I just answered that above. As it was written t had to be less than or equal to the stop hour. Meaning it would not turn off until 19:00. With the new template t has to be less than the stop hour. So will turn off when equal to the stop hour.
Must have posted at the same time
Confirmed and working, thanks a lot for all your help, really appreciate it!
There’s a scheduler card that’s developing nicely that could make this sort of thing a lot easier:
Yeah, I took a look at it, but it was overly complicated for my case and also I couldn’t get it to work properly and/or as I wanted, but indeed, it looks promising, but this’ll do for now