Having an issue with a template; maybe someone sees an obvious problem with this code:
- id: weeklychoresreset
alias: 'Weekly Chores Reset'
trigger:
- platform: time
at: '00:01:00'
action:
- service: input_boolean.turn_off
data_template:
entity_id: >
{% set day = (as_timestamp(now())|timestamp_custom ('%a')) %}
{% if day == 'Sun' %} 'input_boolean.chore_mop_floors'
{% elif day == 'Mon' %} 'input_boolean.chore_vacuum_bedrooms'
{% elif day == 'Tue' %} 'input_boolean.chore_clean_kids_bathroom'
{% elif day == 'Wed' %} 'input_boolean.chore_vacuum_upstairs'
{% elif day == 'Thu' %} 'input_boolean.chore_clean_ensuite'
{% elif day == 'Fri' %} 'input_boolean.chore_vacuum_downstairs'
{% elif day == 'Sat' %} 'input_boolean.chore_sweep', 'input_boolean.chore_clean_down_bathroom'
{% else %} 'none'
{% endif %}
As you can see, the point is for the HA to check what day of the week it is, and turn off one of a number of different boolean switches depending on the day. For example, on Sunday only input_boolean.chore_mop_floors should turn off. Saturday should be both input_boolean_chore_sweep and input_boolean.chore_clean_down_bathroom.
Iâm here because this isnât working (e.g. this morning, input_boolean.chore_clean_kids_bathroom was still on when it should have turned off). Can you guys and gals see anything obviously wrong? This resolves correctly in the template developer tools (i.e. today, Tuesday, it resolves to âinput_boolean.chore_clean_kids_bathroomâ) but it doesnât seem to be correctly passing the entity_id to the turn_off service.
Hmm not sure on this one, just try it with just the comma. If this doesnât work it probably works when you put them into a list. Just come back if it doesnât work
Iâll play around with it and figure out what works. I just asked in case you knew the answer off the top of your head. Thanks a ton for catching that stupid mistake.
I plan on putting this into the âshareâ forum once I get it finished. Itâs actually vaguely elegant, considering the source of the strings (me).
That wasnât a "stupidâ mistake, I looked at the documentation and other posts and came back with nothing definitive and could only suggest what @Burningstone said.
Donât kick yourself over this one, up to today, if Iâd been pushed, Iâd have written it just like you did.
Iâve learnt a wrinkle today (I suspect burning has too) so join the club.
All in all, you wrote a template which was pretty damn close to a solution.
Drink a beer to celebrate
Edit: can you please post your working template, just to help the next guy ?
Iâm definitely at the end of the spectrum where I donât kick myself - Iâm more amused when it actually works if Iâve created it with only minimal copy and paste. Hobbyist coder - itâs still fun for me, even when the mistakes can be rectified with a quick delete. Thatâs my definition of a stupid mistake - not a, âWell, letâs try to recreate that into a function that might actually workâ but instead a, âOh, yeah youâre really not clear when to use â and when to use " (or, when to use neither in this case) in YAML are you?â
Anyway, enough about me, you came here for the recipe (lol). This seems to be working:
- id: weeklychoresreset
alias: 'Weekly Chores Reset'
trigger:
- platform: time
at: '00:01:00'
action:
- service: input_boolean.turn_off
data_template:
entity_id: >
{% set day = (as_timestamp(now())|timestamp_custom ('%a')) %}
{% if day == 'Sun' %} input_boolean.chore_mop_floors
{% elif day == 'Mon' %} input_boolean.chore_vacuum_bedrooms
{% elif day == 'Tue' %} input_boolean.chore_clean_kids_bathroom
{% elif day == 'Wed' %} input_boolean.chore_vacuum_upstairs
{% elif day == 'Thu' %} input_boolean.chore_clean_ensuite
{% elif day == 'Fri' %} input_boolean.chore_vacuum_downstairs
{% elif day == 'Sat' %}
input_boolean.chore_sweep, input_boolean.chore_clean_down_bathroom
{% else %} 'none'
{% endif %}
As you can tell from the above ânot alwaysâ
Hopefully, the above example will dig someone else out of the brown stuff.
Everyday is a learning experience, part of the reason I help out is so I can learn.
You are doing well and have this under your belt.
Happy coding