itm1960
(Itm1960)
April 12, 2023, 11:13am
1
I’m trying to write a script which should only perform the final action if two conditions are met. Both conditions check the status of attributes of a media player entity. I’m getting this syntax error:
Message malformed: extra keys not allowed @ data['sequence'][2]['-conditions']
Could anyone put me straight on how the syntax needs to look? The script is:
alias: Cast EZViz Doorbell Camera to Chromecast
sequence:
- service: media_player.play_media
data:
media_content_id: http://192.168.1.4:81/mjpg/doorbell/video.mjpg
media_content_type: image/jpg
target:
entity_id: media_player.chromecast6791
- service: media_player.play_media
data:
media_content_id: http://192.168.1.4:81/mjpg/doorbell/video.mjpg
media_content_type: image/jpg
target:
entity_id: media_player.kitchen_display
- condition: and
- conditions:
- condition: "{{ is_state('media_player.lg_webos_smart_tv', 'on') }}"
- condition: "{{ is_state_attr('media_player.lg_webos_smart_tv', 'source', 'HDMI 1') }}"
- service: shell_command.pause_humax
data: {}
mode: single
rossk
April 12, 2023, 11:20am
2
Wrong formatting, try:
- condition: and
conditions:
- condition: template
value_template: >-
{{ is_state('media_player.lg_webos_smart_tv', 'on') }}
- condition: template
value_template: >-
{{ is_state_attr('media_player.lg_webos_smart_tv', 'source', 'HDMI 1') }}
itm1960
(Itm1960)
April 12, 2023, 11:48am
3
rossk:
- condition: and
conditions:
- condition: template
value_template: >-
{{ is_state('media_player.lg_webos_smart_tv', 'on') }}
- condition: template
value_template: >-
{{ is_state_attr('media_player.lg_webos_smart_tv', 'source', 'HDMI 1') }}
That gives the same error:
alias: Cast EZViz Doorbell Camera to Chromecast
sequence:
- service: media_player.play_media
data:
media_content_id: http://192.168.1.4:81/mjpg/doorbell/video.mjpg
media_content_type: image/jpg
target:
entity_id: media_player.chromecast6791
- service: media_player.play_media
data:
media_content_id: http://192.168.1.4:81/mjpg/doorbell/video.mjpg
media_content_type: image/jpg
target:
entity_id: media_player.kitchen_display
- condition: and
conditions:
- condition: template
value_template: >-
{{ is_state('media_player.lg_webos_smart_tv', 'on') }}
- condition: template
value_template: >-
{{ is_state_attr('media_player.lg_webos_smart_tv', 'source', 'HDMI 1') }}
- service: shell_command.pause_humax
data: {}
mode: single
Message malformed: extra keys not allowed @ data['sequence'][2]['-conditions']
itm1960
(Itm1960)
April 12, 2023, 11:55am
4
Aah…it was a problem with the indentation of the “service” element - this seems to be accepted:
alias: Cast EZViz Doorbell Camera to Chromecast
sequence:
- service: media_player.play_media
data:
media_content_id: http://192.168.1.4:81/mjpg/doorbell/video.mjpg
media_content_type: image/jpg
target:
entity_id: media_player.chromecast6791
- service: media_player.play_media
data:
media_content_id: http://192.168.1.4:81/mjpg/doorbell/video.mjpg
media_content_type: image/jpg
target:
entity_id: media_player.kitchen_display
- condition: and
conditions:
- condition: template
value_template: >-
{{ is_state('media_player.lg_webos_smart_tv', 'on') }}
- condition: template
value_template: >-
{{ is_state_attr('media_player.lg_webos_smart_tv', 'source', 'HDMI 1') }}
- service: shell_command.pause_humax
data: {}
mode: single
itm1960
(Itm1960)
April 12, 2023, 1:19pm
5
Hmmm…looks like I didn’t resolve it after all…
The final service is never being executed - even when both of the preceding conditions are true.
Any idea why this might be?
- condition: and
conditions:
- condition: template
value_template: "{{ is_state('media_player.lg_webos_smart_tv', 'on') }}"
- condition: template
value_template: >-
{{ is_state_attr('media_player.lg_webos_smart_tv', 'source', 'HDMI 1') }}
- service: shell_command.pause_humax
data: {}