Struggling with what is probably a very basic automation

Very new to this, so apologies if I use the wrong terminology. I thought I’d cracked it, but it’s quite hard for me to test.

I’m trying to send a notification to two phones when (and only when) they are both away from the “home” zone and the garage door is left open. Happens frequently around these parts, and I thought this might be a good practice for something other than the really basic “click here to switch on the light” things I’ve been dealing with before.

I struggle sometimes with logic sadly and my brain goes into shutdown when I try to think it through.

I had set up an automation that said:

when phone 1 leaves home zone
and/if phone 2 leaves home zone
and/if garage door is open
send a notification

Is that the right way to do this?

When I tested it by deliberately leaving the garage door open, the data signal was poor and I needed to go into the automation remotely and run it - I’m using Tailscale to connect. HA home screen knew both devices were “away” from home but nothing had come through automatically. I then closed the garage door remotely.

Whilst I was out, and now I’m back home again, if I run the automation, it rather unhelpfully still notifies me the garage door was left open - but then I guess it’s dealing with the past tense :slight_smile:

I’m getting quite confused clearly.

How would you tackle this?

Thanks for reading.

Post the automation you created (as formatted YAML).

Sincere apologies, didn’t see this response even though notifications is on - one of those days - edit: fixed that in prefs now.

There’s a trigger id in there for some reason, I think I was going to try it a different way to see but forgot to remove it.

alias: Test garage door
description: ""
triggers:
  - device_id: 456a4788923f9cebc139e21135279344
    domain: device_tracker
    entity_id: b2a8bfc7702856835be2f53c96d070e8
    type: leaves
    trigger: device
    zone: zone.home
    id: danout
conditions:
  - condition: device
    device_id: ee12f6235155f1401aa7834d1431fd78
    domain: cover
    entity_id: 7532f235fdf5c829deb27b5269399177
    type: is_open
  - condition: state
    entity_id: device_tracker.holly_iphone
    state: not_home
actions:
  - device_id: 456a4788923f9cebc139e21135279344
    domain: mobile_app
    type: notify
    message: Workshop door was left open
  - device_id: cb731f908f22eb26682a1b57166d48d0
    domain: mobile_app
    type: notify
    message: Workshop door was left open
mode: single

Well if no one is home, the state of your home zone will be 0. Trigger on that and you have a single trigger.

1 Like

This is my trigger no on being home.

entity_id: zone.home
for:
hours: 0
minutes: 0
seconds: 0
below: “1”
trigger: numeric_state

1 Like

That makes perfect sense. I have much to learn clearly, but I shall try and work with that.

And HA will just be monitoring for an event such as this and know to perform the action?

I used the YAML editor and the visual one to create this error :slight_smile:

Message malformed: offset None should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['for']
description: "Garage Door open whilst away from home warning"
mode: single
triggers:
  - entity_id: zone.home
    for: null
    hours: 0
    minutes: 0
    seconds: 0
    below: “1”
    trigger: numeric_state
conditions:
  - condition: device
    device_id: ee12f6235155f1401aa7834d1431fd78
    domain: cover
    entity_id: 7532f235fdf5c829deb27b5269399177
    type: is_open
actions:
  - device_id: 456a4788923f9cebc139e21135279344
    domain: mobile_app
    type: notify
    message: Workshop door was left open
  - device_id: cb731f908f22eb26682a1b57166d48d0
    domain: mobile_app
    type: notify
    message: Workshop door was left open

Use a simple State Trigger.

triggers:
  - trigger: state
    entity_id: zone.home
    to: "0"

EDIT

Correction. Wrapped 0 in quotes to indicate it’s a string.

1 Like

Be careful with indents

Edit: I realize now you just copied the post before which was not posted as a code block.

It creates more issues than it solves when doing that.

1 Like

Was going to try this one as it seemed more elegant (will try both) but I had to wrap the 0 in “” to get past an error - seems a little odd that I’d have to do that, as it’s no longer a number?

alias: Workshop door test 2
description: Garage Door open whilst away from home warning
triggers:
  - triggers:
      - trigger: state
        entity_id: zone.home
        to: "0"
conditions:
  - condition: device
    device_id: ee12f6235155f1401aa7834d1431fd78
    domain: cover
    entity_id: 7532f235fdf5c829deb27b5269399177
    type: is_open
actions:
  - device_id: 456a4788923f9cebc139e21135279344
    domain: mobile_app
    type: notify
    message: Workshop door was left open
  - device_id: cb731f908f22eb26682a1b57166d48d0
    domain: mobile_app
    type: notify
    message: Workshop door was left open

I would also suggest you change your conditions to state conditions and actions to entity actions. It’s more maintainable.

1 Like

Like this?

alias: New automation
description: Garage Door open whilst away from home warning
triggers:
  - triggers:
      - trigger: state
        entity_id: zone.home
        to: "0"
conditions:
  - condition: state
    entity_id: cover.smart_garage_door_2006047904931836100248e1e91e3918_garage
    state: open
actions:
  - device_id: 456a4788923f9cebc139e21135279344
    domain: mobile_app
    type: notify
    message: Workshop door was left open
  - device_id: cb731f908f22eb26682a1b57166d48d0
    domain: mobile_app
    type: notify
    message: Workshop door was left open
mode: single

Yes.

And while you are at it change the actions to … Actions (previously known as service calls).
If you named the phone to say “Wuffls” then when you replace the phone, and you delete the old one and add the new one with the same name, it will just work.
Having it bound to a device id will be lots of work.

The other method some people use is to create a script with the notify phones actions.
That way you can pass the message to the script and run the script.
And when it’s time to replace it, you just change in one place.

1 Like

This is gold, thank you everyone who’s replied.

I actually just did a similar thing with a Christmas Lights automation I’ve done - I created a (forget the word) “group”? for the wifi plugs and called the group name from the automation, so I can add in the correct wifi switches to the group as and when I find them in the attic without changing the script itself.

Would you mind providing a link to what you mean by “Actions” please? It seems to throw up various vagueries referring to action when I try and search. Eager to learn. I assume this is just trying to keep things more object oriented, which clearly means I’m showing my age with my actionscript flashbacks.

It is indeed a bit all over the place. There is a mention of actions under the automations docs which is basically just an anchor, but then also under the script syntax docs here and here, plus every integration has information on its actions in its docs. Mobile notifications via the companion app are even more special, with its docs under the companion app docs.

In this case though, just go to the actions page under the dev tools on your HA instance and start to type notify. Select the one you want (each mobile device using the companion app has its own notify action). Then look at the YAML generated.

Perfect, thank you.

Its a bad decision to say the least from HA developers to call both the automation yaml action and the service calls actions.
Previously they were called call service, which may not make sense to people, but having the same name twice is not great.
Its kind of like naming all your kids the same name. It may seem cute and all but it won’t be great.

Using this method:

Means you are not using device.
You can also do this:


just make sure there is no device id in the yaml and your fine.

About to go out, so will test it - I had this earlier.

alias: New automation
description: Garage Door open whilst away from home warning
triggers:
  - triggers:
      - trigger: state
        entity_id: zone.home
        to: "0"
conditions:
  - condition: state
    entity_id: cover.smart_garage_door_2006047904931836100248e1e91e3918_garage
    state: open
actions:
  - action: notify.mobile_app_nameofphone_iphone
    data:
      message: Workshop door is open
  - action: notify.mobile_app_otherphone_iphone
    data:
      message: Workshop door is open
mode: single

Nope. No message received sadly,