Hey all, looking for some help getting my script to send a timestamp along with it’s notification message. The below script works perfectly. It toggles an MQTT switch, and then waits 5 seconds, and sends a notification to the iOS App, letting me know the new state of the switch:
This script:
works:
vent_mbr_toggle:
sequence:
- service: switch.toggle
entity_id: switch.vent_mbr
- delay: 00:00:05 #added so system has time to switch the state before alerting on it below
- service: notify.ios_sc_phone_hassapp
data_template:
title: "Master Bedroom Vent Status"
message: "is now {{ states.switch.vent_mbr.state }}."
This script:
errors out:
vent_mbr_toggle:
sequence:
- service: switch.toggle
entity_id: switch.vent_mbr
- delay: 00:00:05 #added so system has time to switch the state before alerting on it below
- service: notify.ios_sc_phone_hassapp
data_template:
title: "Master Bedroom Vent Status"
message: "{{ now().strftime("%H:%M %Y-%m-%d") }}: is now {{ states.switch.vent_mbr.state }}."
{{ now().strftime("%H:%M %Y-%m-%d") }}
is the only change in the second example (in the message:
part). I am using the same exact format in some notifications done through the Alert:
component and they work just fine (see examples below). I DO have the time_date
platform loaded in my config.
Two questions:
1. Why this doesn’t work with scripts?
2. How can I get a timestamp to show in my script based notification? is there a different format?
TIA!!
Example of working timestamp in an alert:
based notification:
garage_door:
name: '{{now().strftime("%H:%M %Y-%m-%d")}}: Garage door has been OPEN for {{ relative_time(states.cover.garage_door.last_changed) }}.'
entity_id: cover.garage_door
state: 'open'
repeat:
- 15
- 30
- 60
- 120
can_acknowledge: True
skip_first: True
done_message: '{{now().strftime("%H:%M %Y-%m-%d")}}: Garage door is now closed :)'
notifiers:
- ios_sc_phone_hassapp