I just tried to code the below automations and although the config check passes, when I reload automations I get the below error. It’s the first of the below automations that causes the errors.
Code:
input_boolean:
dog_flea_treatment_reminder:
name: Dog Flea Treatment Reminder
icon: mdi:dog-side
initial: off
automation:
- id: 26ca4631-fc18-4e6c-a7e1-94167d17a160
alias: 'Dog Flea Treatment Reminder'
trigger:
- platform: template
value_template: "{{ now().day == 1 }}"
- platform: time
at: '04:30:00'
condition:
- condition: state
entity_id: input_boolean.dog_flea_treatment_reminder
state: true
action:
- wait_for_trigger:
- platform: time
at: '17:00:00'
- wait_template: "{{ is_state('binary_sensor.kitchen_multi_sensor_sensor', 'on') }}"
timeout: '04:00:00'
continue_on_timeout: false
- service: tts.google_cloud_say #tts.google_translate_say
entity_id: media_player.googlehome3019
data:
message: 'Today is the first of the month so Kingsley is due his flea treatment'
- delay: '08:00:00'
- id: 793de17e-99b8-4edf-ae30-86dcf5ea8961
alias: 'Dog Flea Treatment Reset'
trigger:
- platform: template
value_template: "{{ now().day == 30 }}"
action:
- service: automation.turn_on
entity_id: automation.dog_flea_treament_reminder
- service: input_boolean.turn_on
entity_id: input_boolean.dog_flea_treatment_reminder
Errors:
* Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of print statement', got '=') for dictionary value @ data['value_template']. Got None. (See ?, line ?).
* Invalid config for [automation]: expected str for dictionary value @ data['condition'][0]['state']. Got None. (See ?, line ?).
To explain my thinking here, I want a TTS on the first of the month when someone goes in the kitchen in the evening. I want that TTS to repeat each day until the input_boolean is turned off so it repeats until the job is done.
Given that templates aren’t my forte there is probably a better way of doing the above. I’m open to all suggestions.
Can someone please explain to me what is wrong as the errors aren’t really helping me figure it out.
an input_boolean has only two states “on” or “off”. Not “true” or “false”.
And true/false are seen as boolean values instead of strings (so are on/off as well). And all states are strings so when you use true (without quotes) in a state condition (or trigger) it will complain because it’s not getting a string as a state but instead it gets a boolean value.
so you need to change that state condition to:
condition:
- condition: state
entity_id: input_boolean.dog_flea_treatment_reminder
state: "on"
try that and see if that also might fix the “end of print statement” error too. Maybe the checker gets confused by the first error and then throws the second when not really warranted.
Otherwise I’m not sure where the second error would come from. It looks like the three templates are OK to me.
but to ask a question (or two) on something you didn’t…
Are you sure the logic is OK in the automations?
you have a few “wait_…” conditions and a delay in the first one that don’t make sense to me.
Also be aware that using long delays like that are inherently unreliable since restarts/reloading automations will kill the automation run and it will never meet the conditions until the next time it re-triggers.
And in the second automation why are you turning the first automation on since it doesn’t seem to be turned off anywhere.
If it gets turned off somewhere else then the question becomes why turn it off? You can leave the automation on and use conditions to control it running the actions.
Thanks for that. Not sure why I made that silly mistake. It did fix the errors.
Those are purely to ensure the TTS only occurs in the afternoon and once motion is detected in the kitchen. Looking at it now I should just change the trigger to an afternoon time and use the day of the month check as a condition.
That was a carry over from something else. Now removed.
Also now removed as I was playing with a few options.
I’ve re-written the automations to simplify things. Hopefully the below will work as a better solution.
I really try to stay away from any delay/wait over 5 minutes unless it’s not a big deal if the automation actually runs the actions or not or I have a backup method to ensure the actions run.
I typically use an input_datetime set for the long delay so if the automation gets reset due to a reload etc it still triggers at the right time.
In your case I don’t think that will work tho.
But looking at it again couldn’t you instead trigger on motion and use the time(s) as conditions to make it run when desired?
something like:
- id: 793de17e-99b8-4edf-ae30-86dcf5ea8961
alias: 'Dog Flea Treatment TTS'
trigger:
- platform: state
entity_id: binary_sensor.kitchen_multi_sensor_sensor
to: "on"
condition:
- condition: time
after: "17:30:00"
before: "21:30:00"
- condition: state
entity_id: input_boolean.dog_flea_treatment_reminder
state: "on"
action:
- service: tts.google_cloud_say #tts.google_translate_say
entity_id: media_player.googlehome3019
data:
message: 'Kingsleys flea treatment is due'
That would actually work quite well in that it would cause the TTS to repeat each time there is motion in the kitchen until the input boolean is turned off (ie: task completed) but I’ll add a delay at the end so it doesn’t get repeated too soon after the previous one.