using a ‘repeat while’ causes me headaches, please help me out, what am I doing wrong?
this works perfectly:
intercom_alarm:
alias: Intercom alarm
mode: queued
sequence:
- service: media_player.volume_set
data:
entity_id: &alarm_players
- media_player.googlehome_hub
- media_player.googlehome_hall
- media_player.googlehome_master_bedroom
volume_level: 0.6
# - alias: repeat while alarm is armed
# repeat:
# while: >
# {{states('alarm_control_panel.ha_rpi4_alarm') in ['armed_away','armed_home']}}
# sequence:
- service: tts.google_say #tts.cloud_say
data:
language: >
{{states('input_select.intercom_language')|lower}}
entity_id: *alarm_players
message: >
{% set language = states('input_select.intercom_language') %}
{% if language == 'En' %} {{message_en}}
{% elif language == 'Nl' %} {{message_nl}}
{% else %} {{message_en}}
{% endif %}
- service: media_player.volume_set
data:
entity_id: *alarm_players
volume_level: 0.3
but when I uncomment the repeat, nothing is played at all. What did I miss in the syntax/logic? There is no error in the log at all, and config checks fine.
intercom_alarm:
alias: Intercom alarm
mode: queued
sequence:
- service: media_player.volume_set
data:
entity_id: &alarm_players
- media_player.googlehome_hub
- media_player.googlehome_hall
- media_player.googlehome_master_bedroom
volume_level: 0.6
- alias: repeat while alarm is armed
repeat:
while: >
{{states('alarm_control_panel.ha_rpi4_alarm') in ['armed_away','armed_home']}}
sequence:
- service: tts.google_say #tts.cloud_say
data:
language: >
{{states('input_select.intercom_language')|lower}}
entity_id: *alarm_players
message: >
{% set language = states('input_select.intercom_language') %}
{% if language == 'En' %} {{message_en}}
{% elif language == 'Nl' %} {{message_nl}}
{% else %} {{message_en}}
{% endif %}
- delay:
seconds: 10
- service: media_player.volume_set
data:
entity_id: *alarm_players
volume_level: 0.3
this is the service in the automation calling the script:
- service: script.intercom_alarm
data:
message_nl: >
{% set room = trigger.to_state.object_id.split('_sensor_motion')[0].replace('_',' ')|capitalize %}
Alarm, {{room}} heeft beweging gesignaleerd,
controleer wat er aan de hand is!
message_en: >
{% set room = trigger.to_state.object_id.split('_sensor_motion')[0].replace('_',' ')|capitalize %}
Alarm, {{room}} triggered the alarm, check whats up!
which as said, works as expected. So must be the script.
update
using a repeat-until syntax does work fine:
intercom_alarm:
alias: Intercom alarm
mode: queued
sequence:
- service: media_player.volume_set
data:
entity_id: &alarm_players
- media_player.googlehome_hub
- media_player.googlehome_hall
- media_player.googlehome_master_bedroom
volume_level: 0.6
- alias: repeat until alarm is disarmed
repeat:
sequence:
- service: tts.google_say #tts.cloud_say
data:
language: >
{{states('input_select.intercom_language')|lower}}
entity_id: *alarm_players
message: >
{% set language = states('input_select.intercom_language') %}
{% if language == 'En' %} {{message_en}}
{% elif language == 'Nl' %} {{message_nl}}
{% else %} {{message_en}}
{% endif %}
- delay:
seconds: 10
until: >
{{is_state('alarm_control_panel.ha_rpi4_alarm','disarmed')}}
- service: media_player.volume_set
data:
entity_id: *alarm_players
volume_level: 0.3
cant find the issue with the ‘while’ loop though… for a minute I thought the a delay would be causing trouble, but after I’ve added that (edited the post in the example above with that) doesn’t make a difference.
please have a look? Thanks!