Hi, how to do something like below? Do a different type of message action depending on current state (sun):
- id: '1553163933856'
alias: Motion detected
description: ''
trigger:
- entity_id: input_boolean.motion_sensor
from: 'off'
platform: state
to: 'on'
condition: []
action:
- service: notify.notify
data_template:
message: Motion detected in the back!
data: >
{% if is_state('sun.sun', 'above_horizon') %}
push:
sound:
name: Google-Motion-Detected.wav
critical: 1
volume: 1.0
{% else %}
push:
sound: Google-Motion-Detected.wav
{% endif %}
Thanks!
micque
(micque)
July 1, 2020, 1:42pm
2
Same way as has been done for data. Copy the data code into message, remove push: code, replace with chosen text messages. Data_template doesn’t only work for a data section. It allows you to template any section.
Hi, thanks for the reply. Can you give me an example, please? Thanks!
micque
(micque)
July 1, 2020, 8:38pm
4
Here you go.
action:
- service: notify.notify
data_template:
message: >
{% if is_state('sun.sun', 'above_horizon') %}
message one
{% else %}
message two
{% endif %}
data: >
{% if is_state('sun.sun', 'above_horizon') %}
push:
sound:
name: Google-Motion-Detected.wav
critical: 1
volume: 1.0
{% else %}
push:
sound: Google-Motion-Detected.wav
{% endif %}
Sorry, I’m getting this error:
Error executing script. Invalid data for call_service at pos 1: expected dict for dictionary value @ data[‘data’]
micque
(micque)
July 1, 2020, 9:50pm
8
It’s complaining about the data: portion of your script. I don’t know what push:, etc. is so I don’t know how to help.