Hi everyone,
Total newbie here, and if there’s a thread on this, I couldn’t find a helpful one via the search (sorry just point me to it!).
So a great feature in SmartThings was the goodnight automation. For me, with no movement after say 9pm, lights and some switches downstairs would turn off.
Trying to replicate that in HA is really not working for me, can anyone advise what I’m doing wrong please?
Right now I think I have it set to:
Wait for no movement on my motion sensors
AND
Wait for my Nest Protects to show no room occupancy
AND
Wait for my SmartThings Goodnight virtual Switch to be off (it’s inversed)
AND
Wait for the time to be after 20:57
Despite all the above, everything turns off at 20:57.
I’m trying to retire SmartThings, but the Goodmorning, Goodnight and alarm functions are things I’m struggling to workout in HA.
Any help on what I’ve done wrong would be greatly appreciated.
Sorry if I’m wrong; I’ve never used the HA Automation interface.
But, if I tried to reproduce your automation in NodeRed, it would not function since the logic and/or order is flawed. Currently, you have one condition and three distinct triggers. Hence, the automation will just fire if any of those triggers activate after 20:57.
So, right now I think you have it set to:
Wait for no movement on my motion sensors
OR
Wait for my Nest Protects to show no room occupancy
OR
Wait for my SmartThings Goodnight virtual Switch to be off (it’s inversed)
AND
Wait for the time to be after 20:57
Simply choose one of those to serve as the trigger, and the others as conditions. I don’t know what the most logical trigger would be in your setup as I don’t know what the switch does, but yeah. I hope you get what I mean (I’m not a native speaker)
I think what I am trying to achieve is have all my triggers have an “AND” instruction between them, right now I think they’ve defaulted to an “OR” instruction.
Create a Group Binary Sensor containing the 8 motion detectors. For example purposes, let’s say you name it binary_sensor.all_motion.
Create another Group Binary Sensor containing all five occupancy detectors (called binary_sensor.all_occupancy).
Use the following automation:
alias: (HA) Goodnight Automation
description: ""
trigger:
- platform: state
entity_id: binary_sensor.all_motion
to: "off"
for:
minutes: 15
- platform: state
entity_id: binary_sensor.all_occupancy
to: "off"
for:
minutes: 20
- platform: state
entity_id: switch.ha_power_down_v_switch
to: "off"
condition:
- condition: time
after: "22:30:00"
before: "06:30:00"
- condition: state
entity_id: binary_sensor.all_motion
state: "off"
- condition: state
entity_id: binary_sensor.all_occupancy
state: "off"
- condition: state
entity_id: switch.ha_power_down_v_switch
state: "off"
action:
- service: notify.notify
data:
title: Home Power Alert
message: Goodnight! Powering down switches and lights for the night.
- service: homeassistant.turn_off
target:
entity_id:
- light.lights_porch
- switch.nspanelgarage_relay_1
- switch.nspanelgarage_relay_2
- light.christmas_tree
- switch.lounge_wal
- switch.light_garden_wall_led_strip
- delay:
minutes: 3
- service: switch.turn_off
target:
entity_id: switch.nspanel_garage_relay_1
mode: single
Try that and let me know if it needs further refinement. For example, I would add a Time Trigger at 22:30. If there’s already no motion or occupancy prior to 22:30 (i.e. no one is home or everyone went to bed early), at 22:30 the automation will turn off the specified lights and switches.
Thanks @123 I’ll give this a go tomorrow.
Question though, does your yaml contain the “OR” command I’m looking for?
If so, can I not just format my original automation to include it too?
Multiple triggers are, by default, logically ORed. They can’t be logically ANDed because that would require two events to occur at the exact same moment in time (i.e. front door AND back door closing at the exact same time).
Multiple conditions are, by default, logically ANDed. They can be also be ORed or a combination of ANDed and ORed.
Hi @123 I just wanted to say thank you, this worked!
Logically speaking, I don’t get why my original one didn’t work though, but at least it’s working now.
I’ve also learnt about group binary sensors which I’ll now use elsewhere.