Hi!
I have written a script that should send a notification if a given person is home.
When I call the script from automation, the variables are not set correctly.
The notification is always send for jane and not for john
Before the script I had everything inside the automation, but I wanted to extract the logic, because I want to use the logic for several automations and users/devices.
What have I done wrong?
my script:
alias: notify_humidity_alert
mode: queued
description: Send a notification if the humidity is too high
sequence:
- alias: Set fields
fields:
humidity:
description: "The humidity"
example: "75"
room:
description: "The room"
example: "Man Cave"
myperson:
description: "For whom"
example: "person.jane"
mobile_app:
description: "The device"
example: "notify.mobile_app_jane"
- if:
- condition: template
value_template: "{{ states(myperson) == 'home' }}" # send notification only if person is home
then:
- action: "{{ mobile_app }}"
metadata: {}
data:
message: The humidity ({{ humidity }}%) is too high in the room "{{ room }}".
title: Warning!
data:
clickAction: /dashboard-caves/man-cave
The section in my automation:
- action: script.notify_humidity_alert
alias: Notify John
metadata: {}
data:
humidity: "{{ states('sensor.man_cave_humidity') | int }}"
room: "{{ area_name('sensor.man_cave_humidity') }}"
myperson: person.john
mobile_app: notify.mobile_app_john_tablet