Alexa, In XX time, Take Action

Objective: Alexa, in 15 minutes, turn off lights.

Is there a way to enable this using the Amazon Alexa Smart Home skill and exposed items? I can’t seem to find anything on this. Via experiments, Alexa seems to take the request but fails to wait before taking the action.

Unfortunately, to my knowledge, there is no concept of duration part of the Alexa Smart Home API as of yet.

However you could use an Alexa routines and the wait action. It’s obviously not optimal as you will need to create a routine for each duration value you intended to use.

Another option would be to use a setup similar to what I described in the below tutorial, with the help of the Amazon Echo Control binding. That way, you could extract the duration value from the voice command and set a timer on the OH side.

May be not exact what you want; let me describe what I do:
Sometimes we want to have light at the outside for 5 or for 10 minutes.
So I created these items:

Switch Rule_Fuenf_Minuten_Aussenlicht_einschalten "Fuenf_Minuten_Aussenlicht" ["Switchable"] { expire="300s,command=OFF" }
Switch Rule_Zehn_Minuten_Aussenlicht_einschalten "Zehn_Minuten_Aussenlicht" ["Switchable"] { expire="600s,command=OFF" }

And related rules because I need to control the switch via telnet command:

rule "rule triggered by Rule_Fuenf_Minuten_Aussenlicht_einschalten"
when 
        Item Rule_Fuenf_Minuten_Aussenlicht_einschalten received command
then
        if (receivedCommand === ON ) {
                executeCommandLine( "/etc/openhab2/scripts/aussenlicht.sh OUT4  1" )
        }
        else if ( receivedCommand == OFF ) {
                executeCommandLine( "/etc/openhab2/scripts/aussenlicht.sh OUT4  0" )
        }
end


rule "rule triggered by Rule_Zehn_Minuten_Aussenlicht_einschalten"
when 
        Item Rule_Zehn_Minuten_Aussenlicht_einschalten received command
then
        if (receivedCommand === ON ) {
                executeCommandLine( "/etc/openhab2/scripts/aussenlicht.sh OUT4  1" )
        }
        else if ( receivedCommand == OFF ) {
                executeCommandLine( "/etc/openhab2/scripts/aussenlicht.sh OUT4  0" )
        }
end

This also works if the lights are already on so they will be switched off in 5 resp. 10 minutes.
Expire is done by jpython helper library not the binding.

If it’s always 15Minutes, you could expose an item to Alexa, which expires automatically after 15minutes and have a rule in place which turns off the lights, if this proxy item goes OFF…

Regarding the Alexa room awareness …

If I give Alexa a command, she acts on it and responds. If I use an openhab rule to act/respond, is there a way to prevent Alexa from doing it?

Yes to some degree. This is why part of that setup is to use a dummy Alexa activity item so that it received the command and act the way you want on the OH side based on the voice command.

Anyway, I just posted an update to my original tutorial adding that support. Not sure if this would help as this is for English language and it is limited to turn on/off action only but that should give you an idea on how it could be implemented.

For reference, Alexa now supports requests for turning on and off a given device, group or scene at a specific time or after a desired amount of time up to 24 hours in the future. It is not clear if this is supported across all languages.

1 Like