I’m trying to figure our how the concept working with states etc and how to catch and make actions.
My particular issue that I’m trying to solve is to either send an alert or turn on the lights. Send an alert if no one is home (have a template for that with either yes or no) or if the sun is below horizon.
If we are home and the sun is above horizon the lights should turn on.
It is possible to have this in one automation rule or do I have to create several?
I know that I can create automations to check if we are not home and garage door i open, as well if the sun is down and garage door is open to send notes, but trying to optimize the automation rules and in same time understand better how the states and what triggers what and when.
Any help or directions how to look is highly appreciated
Thanks,
Peter
Will the automation trigger still be garage door state, i.e. as long it’s in on state the service call will ke on decide what to do? Or do HA only trigger once and when it goes to on state?
I’d guess if I set to only on state and not from off to on HA gets trigger?
I think I have started for what I aiming for, but do not get the result as I want. Not sure if I’m on right track or not.
I thought that if I do a template trigger the automation will trigger the whole time and not only when the state changes. The goal is to have following.
when we are home, and the door open, the light will turn on.
when we leave the home and the door is still open or if it opens when we are not home the message will fire off.
Can I do like this or do I need to think trigger and for all actions that I want to happen for each trigger will be taken care of that trigger?
Thanks,
- id: send_msg_if_garage_door_is_open_and_no_home
alias: Garage Door is open
trigger:
- platform: template
value_template: "{% if is_state('binary_sensor.garagedorren', 'on') %}true{% endif %}"
action:
- service: homeassistant.turn_on
entity_id: switch.fonster_kontor
- condition: state
entity_id: sensor.someone_home
state: 'no'
- service: notify.ios_petersiphone
data:
message: "Garage door is open!"
when the door opens, if you are home, the light will turn on, if you are not home, it will send you a warning.
when you leave home, if the door is open send you a warning.
I suggest you do these as two separate automations:
NOTE: the below is psuedo-code. I have made no effort to validate the spacing or values.
alias door_open
trigger :
platform: state
entity_id: binary_sensor.garagedorren
to : 'on'
action:
service_template :>
{% if is_state(sensor.someone_home,'home')%}
homeassistant.turn_on
{%else%}
notify.ios_petersiphone
{% endif %}
data_template :>
{% if is_state(sensor.someone_home,'home')%}
switch.fonster_kontor
{%else%}
message: "Garage door is open!
{% endif %}
Then the second automation for when you leave:
alias weLeft
trigger:
platform: state
entity_id: sensor.someone_home
to : away
condition:
condition: state
entity_id: binary_sensor.garagedorren
state : 'on'
action:
- service : notify.ios_petersiphone
data:
message: "Come Back, the garage door is open!"
I’ll guess that I’m still not completely understand the service template concept.
Formatting your input, results in errors. I see that a reference to device id is missing (or needed), however, I can not get to the point to understand if all device Id that is in the template shall be listed or what.
Perhaps this is over my head, but thinking I grow with the task and learning by doing the hard work.
I messed around with this for quite a while in my test environment, and I can’t make it work with two automations.
Here is how it would work with 3 automations. Some of your switch values may be different.
- alias: door open
trigger:
platform: state
entity_id: binary_sensor.garagedorren
to : 'on'
condition:
condition: state
entity_id: sensor.someone_home
state: 'not home'
action:
service: notify.ios_petersiphone
data:
message: "Garage door is open!"
- alias: door open 2
trigger:
platform: state
entity_id: binary_sensor.garagedorren
to : 'on'
condition:
condition: state
entity_id: sensor.someone_home
state: 'home'
action:
service: switch.turn_on
entity_id: switch.fonster_kontor
- alias: weLeft
trigger:
platform: state
entity_id: sensor.someone_home
to : away
condition:
condition: state
entity_id: binary_sensor.garagedorren
state : 'on'
action:
service : notify.ios_petersiphone
data:
message: "Come Back, the garage door is open!"