Hi,
I am trying to build a script which counts the number of minutes a sensor has been open for, and then sends this using a script I use to send iMessages and then tts the same info:
loop_front_gate_open_1:
alias: Loop Front Gate Open 1
sequence:
- condition: state
entity_id: binary_sensor.front_gate
state: 'on'
- delay:
seconds: 5
- service: counter.increment
entity_id: counter.front_gate_open_time
- service: shell_command.send_imessage
data_template:
entity_id: counter.front_gate_open_time
message: 'INFO - THE FRONT GATE HAS BEEN OPEN FOR {{ states("counter.front_gate_open_time") }} minutes.'
- service: script.turn_on
entity_id: script.loop_front_gate_open_2
- condition: state
entity_id: input_boolean.notify_tts_info_alerts
state: 'on'
- service: tts.macos_say
entity_id:
- media_player.hallway
- media_player.gym
- media_player.macmini
data_template:
message: 'Warning - the front gate has been open for {{ states("counter.front_gate_open_time") }} minutes.'
In the log I get:
2018-12-30 18:57:46 ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: ‘counter’ is undefined
Any help much appreciated!