But like this you cannot have a fraction of an hour (e.g. 10 minutes)
Tell me the exact range you want, forget fractions of an hour. What is the minimum, what is the maximum?
From 10 to 240 minutes. With one input_number only though
Then set your input number to have a minimum of 10 and a maximum of 240 and forget the math in your template.
But that will be in seconds, not minutes - am I wrong?
Not if you do this:
for:
minutes: "{{ states('input_number.laundryroom_ventilation_timer') }}"
I would say you will need to do a bit more fancy templating.
I haven’t been able to test it but I think this should work
trigger:
- entity_id: fan.laundryroom_ventilation
for:
hours: >
{% if states(''input_number.laundryroom_ventilation_timer'')|int > 59 %}
{{ (states(''input_number.laundryroom_ventilation_timer'')|int / 60 ) | int }}
{% else %}
0
{% endif %}
minutes: >
{% if states(''input_number.laundryroom_ventilation_timer'')|int > 59 %}
{{ states(''input_number.laundryroom_ventilation_timer'')|int % 60 }}
{% else %}
{{ states(''input_number.laundryroom_ventilation_timer'')|int }}
{% endif %}
Wasn’t there a recent change that made minutes over 59 no longer work and you have to use explicit hours & minutes?
Pretty sure that’s time_pattern triggers only. I’ll test it tomorrow. Bed time was hours ago.
Yeah, I think you’re right.
Maybe this was affected as well and undocumented?
Then again I’ve never templated “for:” before so maybe it has always been that way.
What was the error?
The timer is simply ignored and nothing happens
@finity I get the following error
Invalid config for [automation]: expected int for dictionary value @ data['trigger'][0]['for']['hours']. Got None
expected int for dictionary value @ data['trigger'][0]['for']['minutes']. Got None. (See ?, line ?).
When using the following code:
- alias: Laundryroom ventilation timer
trigger:
- entity_id: fan.laundryroom_ventilation
for:
hours: >
{% if states(''input_number.laundryroom_ventilation_timer'')|int > 59 %}
{{ (states(''input_number.laundryroom_ventilation_timer'')|int / 60 ) | int }}
{% else %}
0
{% endif %}
minutes: >
{% if states(''input_number.laundryroom_ventilation_timer'')|int > 59 %}
{{ states(''input_number.laundryroom_ventilation_timer'')|int % 60 }}
{% else %}
{{ states(''input_number.laundryroom_ventilation_timer'')|int }}
{% endif %}
platform: state
to: 'on'
condition: []
action:
- entity_id: fan.laundryroom_ventilation
service: homeassistant.turn_off
initial_state: true
mode: single
I just created some test entities and re-created your automation above and ended up with a similar error.
I found that, strangely (or maybe not now that I think about it… ), the template interpreter didn’t like the double single quotes. Once I removed one set of single quotes it seems to be working fine (at least for values less than 60…I didn’t want to wait an hour to see if it turned back off ).
So, try this:
- alias: Laundryroom ventilation timer
trigger:
- entity_id: fan.laundryroom_ventilation
for:
hours: >
{% if states('input_number.laundryroom_ventilation_timer')|int > 59 %}
{{ (states('input_number.laundryroom_ventilation_timer')|int / 60 ) | int }}
{% else %}
0
{% endif %}
minutes: >
{% if states('input_number.laundryroom_ventilation_timer')|int > 59 %}
{{ states('input_number.laundryroom_ventilation_timer')|int % 60 }}
{% else %}
{{ states('input_number.laundryroom_ventilation_timer')|int }}
{% endif %}
platform: state
to: 'on'
condition: []
action:
- entity_id: fan.laundryroom_ventilation
service: homeassistant.turn_off
initial_state: true
mode: single
Still not sure why you are jumping through all these hoops when you can do this:
That method won’t work if it’s over 60 minutes. His method does.
Ah, so that is a limitation for more than just the time pattern trigger. Seems to be an unjustified limit here.
I might be wrong… You might be right… I’d need to do tests. You can quickly figure this out if you put in 61 minutes and the yaml complains at you.
I think you are correct, I don’t think there’s a limitation. So yeah, your for template should work fine. I’ll let you know in 70 minutes.