Help with simple door open routine


#1

Hi all…very simple one here, kind of building on some other ones I’ve seen here and tried to get working.

I’ve got a simple piston going to where when I run a routine “Door Test”, if a door is open (Garage, Door from Garage, Patio Door, Front door) is open Alexa will tell me which door is open, and that’s working. What I’d like to add is something to the end where if they are all closed when I run the routine, I’d like her to say “All doors are closed.”

I know it’s simple, but the coding is still something I’m learning. Thanks for this great community!


#2

It looks like you are executing ‘door test’ which triggers this piston. Why not just execute this piston directly? I think the simplest way to do what you want is to make your second condition (any contact sensor open) an indentured if rather than part of the top level. Then you can use your else for ‘all doors are closed’. like this:

if routine executes Door Test
then
  if any sensor open
    save matching to sensors_open
  then
    speak sensors_open
  else
    speak 'All doors closed'
  end if
end if

#3

Thanks! I’m actually trying to figure out which way I want to trigger it, as of now, my thought was just to run a routine before we go to bed. So it will run through and tell me if/what door is open. How would I add “____door has been open for __ minutes” ?


#4

@Billb1981 I have never done it before but I believe you would need to replace ‘speak sensors_open’ above with the following snippet:

for each sensors_open
  with 
     Music Player 4
  do
      speak {$device} has been open for {age([$device:contact])}
  end with
end for