as you can see the trigger has the attribute from_state: null
I would like to filter my automation not to process if the form_state is null.
How can I do this? I already tried the following options:
trigger:
- platform: state
entity_id: light.ds_hauptbad_light2
condition: "{{ trigger.from_state is defined }}"
# condition: "{{ trigger.from_state != null }}
# condition: "{{ trigger.from_state != 'null' }}"
Long three years since either of you have probably looked at this, but I have the same question, and don’t know if the solution here will work or if I’m just doing something incorrectly.
So, I’m trying to add an if-then action to an existing automation. The English version is that it’s an automation that simply uses a camera’s person sensor as a trigger, takes a picture, then sends that picture and actionable notice to a mobile device.
But… there’s four people in the house, and we all tend to get different phones/devices on different schedules, and device names change all the time (along with apps). So, rather than finding/changing the automations when someone does that, I started by editing the original automation with just the first device/app name variable, via a helper. Once I got that working perfectly, I figured I’d build out the other three as helper variables as well, but plan on if the kids move out, etc., maybe having 1-2 being blank in the future. So… I’m trying to get Helpers 2-4 to be if-then actions.
I’ve conceived this as "If Helper 2 variable is not empty, then send the notification and picture, then move on to Helper 3, then Helper 4… etc. The code below is the if-then for Helper 2 only, and it doesn’t work. I am NOT a YAML person at all, so hopefully this doesn’t make you laugh too hard. But really, it’s only the first part about triggering off of the NULL value in the Helper 2 that isn’t working.
alias: >-
If Mobile App 2 Helper NOT SET to NULL, then send notice and picture there as
well.
if:
- condition: template
value_template: |-
trigger:
- platform: state
entity_id: input_text.mobile_app_2
condition: "{{ trigger.from_state is not none }}"
then:
- action: notify.mobile_app_{{ states('input_text.mobile_app_2') }}
data:
data:
image: https://mydomain/local/photos/Driveway.jpg
actions:
- action: URI
title: Open Home Assistant Views
uri: /lovelace/yard
message: Person Detected
title: "Driveway:"
alias: >-
Send notification with picture to user of device named in Mobile App 2
helper variable.
else: []
You put yaml in the value_template, it should just be the template. I.e. the “{{ … }}”. Make sure you only use single line notation. Put it on the same line and drop the |-
Thank you for the quick reply! It was with this, and other posts, youtube videos, and information that I ended up giving myself more of a crash course in templates than I’d expected. I eventually just created binary sensors for my helpers, so “helpers for helpers”, using the template coding:
{% if states('input_text.mobile_app_1', 'is not none') %}
{{ True }}
{% else %}
{{ False }}
{% endif %}
(Where the number 1 is 1-4, for the four different text input helpers.) Now the notifications with pictures being sent to phones when cameras detect people work perfectly, and they just don’t send anything when one of the helper variables is blank.