Looking for some help - I can’t seem to make the leap here to get this working.
I’m using GCal to set rgb colours on certain days of the year (green for St Patrick’s day, orange for halloween etc etc). Automation regularly checks the calendar and populates the agenda
var.
I loop over the agenda
, looking for a summary match (“BloomColour”) and if it exists I want to extract the message data that should contain the rgb code (0,255,0). When the BloomColour event isn’t present, I want to set the colour back to an empty string.
If I run the calendar.get_events in devtools/services, copy the output yaml → json and then post it into the Template editor with the appropriate name, the following for-loop works fine - I can see the {{target_colour}}
value being printed out.
{%- for key, value in agenda.items() %}
{%- for event in value.events if 'BloomColour' in event.summary %}
{%- set target_colour = event.message %}
{%- endfor %}
{%- endfor %}
{{ target_colour }}
When I run the full automation, the value doesn’t change from an empty string.
....
action:
- service: calendar.get_events
target:
entity_id: calendar.homeassistant
data:
duration:
hours: 24
response_variable: agenda
- variables:
target_colour: ''
- if:
- condition: template
value_template: |-
{%- for key, value in agenda.items() %}
{%- for event in value.events if 'BloomColour' in event.summary %}
{%- set target_colour = event.message %}
{{ 'true' }}
{%- endfor %}
{%- endfor %}
then:
- service: notify.slack_notification
data:
message: "{{ target_colour }}"
target: debug
- service: input_text.set_value
data:
value: "{{ target_colour }}"
target:
entity_id: input_text.colour_to_use
- service: input_boolean.turn_on
target:
entity_id: input_boolean.special_alarm
else:
- service: input_text.set_value
data:
value: ""
target:
entity_id: input_text.colour_to_use
- service: input_boolean.turn_off
target:
entity_id: input_boolean.special_alarm
I’ve tried using:
- service: input_text.set_value
data:
value_template: |
{{ target_colour }}
target:
entity_id: input_text.colour_to_use
but this just throws errors (“Error: extra keys not allowed @ data[‘value_template’]”).
Traces tells me it’s hitting the right path in the if-then-else statement, it’s just not populating.
Can someone explain why the {{target_colour}}
input_text not updating in the automation? Pretty sure it’s simple, I’m just too close to see it.
A final question, is there a more elegant way to make the true/false work in the if-then-else rather than manually putting {{‘true’}} in the template block? I’m sure there is, but my brain is a bit fried over this.
3 posts - 2 participants
Read full topic