Reliable timers for always on/timed/off lamps

Goufalite
  • Reliable timers for always on/timed/off lamps Goufalite

    I have a ZWave light bulb and a ZWave 4-button wall switch, both connected to Domoticz installed on a Raspberry Pi.

    I'd like the following scenarios :

    • Button 1 : lamp on for 30 minutes
    • Button 2 : lamp off
    • Button 3 : lamp always on
    • Button 4 : summon Cthulhu

    Each buttons overrides the previous action (Button 3 -> Button 1 = on for 30 minutes)

    Wiring and programming the buttons is easy, but now, how about the timer ? I'd like to avoid creating a homemade service because I'm afraid of messing with init.d.

    I have 3 possibilities :


    Domoticz dummy switch

    Domoticz allows to create a dummy switch which can change states after some time given in an interface :

    domoticz dummy switch

    Pros

    • off-the-shelf timer!
    • I can interact quite quickly between my wall switch and the lamp

    Cons

    • although Domoticz handles MQTT, there will be a lot of LUA script and "blocky" to interconnect devices
    • time might not be easily configurable...

    at and atq

    at is a linux command to plan an action in time, as simple as

    at [when] < [what]
    

    Pros

    • multi-timer service
    • easy to use and call

    Cons

    • at only gives an unique ID, unless parsing the planned command I can't give a name to the job (unless with a magic linux command...)
    • therefore I need to code/implement a job matcher using a database

    Crontab

    Crontab is a linux service to plan repetitive tasks. In my case it will be a simple

    # check every minute
    * * * * * /path/checktimer.sh
    

    Pros

    • Reliable time trigger

    Cons

    • Cannot manage seconds...
    • Still forced to maintain somewhere a job matcher

    To my question :

    • Did you have to manage timers like this kind?
    • Did I miss other more reliable/configurable solutions?
    • Do you have a preference with on the solutions above?

  • Per request I'll try to give an example on how I would tackle it (with bash shell jobs handling):

    Button 1:
    When turning on a lamp X for 30 seconds and lamp Y for 5 minutes:

    echo "Switch on lamp_x" && sleep 30s && echo "Switch off lamp_x" &
    echo "Switch on lamp_y" && sleep 5m && echo "Switch off lamp_y" &
    

    Due to process limitations, this has to be on two separate lines, the echo above should be replaced by actual commands obviously.

    button 3:
    You can then kill sleep to stop it and keep the light on by getting a job pid and killing it:

    kill $(jobs -p %?lamp_y)
    echo "Switch on lamp_y"
    

    The fact the commands are chained by && will prevent the command after sleep to run as sleep didn't exit properly.
    This doesn't handle non existing job, which may cause kill to return an error, nothing bad should happen here.

    Button 2: Using the same method as button 3, but using the stop command and killing the jobs if any.

    Button 4:

    echo "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn"
    

    (sorry I've no idea what you wish here, set for completeness)


    Details of implementations about jobs:

    jobs -p %?lamp_y return the current pid -p of a job matching the jobspec %?lamp_y which means lamp_y may appear anywhere in the command line, choose carefully what to use here (but I bet you have a unique identifier for things or group of things you wish to control).

  • If you want to use an online service for this, you should be able to use https://www.stringify.com They support sequences and variables (and timers). I've not used their service in anger, but it looks like you should be able to use a timer to decrement a variable (which determines the remaining on time), and the various trigger events can force the variable to a new value.

    They support IFTTT integration, so pretty much any endpoint can be linked in some way.

  • I've found another way quite expensive yet working with external processess such as PHP's system : screen

    First, install it :

    sudo apt-get install screen
    

    Then call your function

    screen -dm -S taskid bash -c 'sleep 20 && command'
        -dm : detach process
        -S  : identify screen by name
    

    To list your tasks

    ls /var/run/screen/S-www-data (or S-anotheruser, warning it is user bound, or sudo it)
    

    To kill it

    screen -S taskid -X kill
        -S : identify screen by name
        -X : access the screen and perform this command
    

Tags
smart-home domoticz
Related questions and answers
  • I have a ZWave light bulb and a ZWave 4-button wall switch, both connected to Domoticz installed on a Raspberry Pi. I'd like the following scenarios : Button 1 : lamp on for 30 minutes Button 2 : lamp off Button 3 : lamp always on Button 4 : summon Cthulhu Each buttons overrides the previous action (Button 3 -> Button 1 = on for 30 minutes) Wiring and programming the buttons is easy... a dummy switch which can change states after some time given in an interface : Pros off-the-shelf timer! I can interact quite quickly between my wall switch and the lamp Cons although Domoticz

  • I'm having a but of trouble making sure my project really is feasible. What I want to archive: Control my Senseo coffee machine via internet. It boils down to simply controlling 2 buttons. First easy solution: Setup a NodeJS server on my Raspberry Pi. I plug my Raspberry GPIOs to 2 transistors, to control the coffee machine buttons I can control the Raspberry GPIO directly in Javascript... coffee did you drink this year ?) ESP8266: Uses NodeMCU. Its GPIOs are plugged to a transistor controlling the coffee machine buttons. I don't care about how to power the ESP8266. It runs a web server

  • I'm having a but of trouble making sure my project really is feasible. What I want to archive: Control my Senseo coffee machine via internet. It boils down to simply controlling 2 buttons. First easy solution: Setup a NodeJS server on my Raspberry Pi. I plug my Raspberry GPIOs to 2 transistors, to control the coffee machine buttons I can control the Raspberry GPIO directly in Javascript... coffee did you drink this year ?) ESP8266: Uses NodeMCU. Its GPIOs are plugged to a transistor controlling the coffee machine buttons. I don't care about how to power the ESP8266. It runs a web server

  • environment. Now, when I want to use Alexa, instead of waking it up directly I would use my proxy, that would somehow enable Alexa's microphone and switch Alexa into Listening state. When Alexa goes back to Idle the proxy should automatically switch it to Microphone Off state. What I need in general are: The proxy should know Alexa's current state. Won't be the best solution but I may can... voice command to the proxy device. More precisely it should be able to switch Alexa between its following states. Idle: When Alexa is idle, customers can use the Alexa wake word or a physical

  • environment. Now, when I want to use Alexa, instead of waking it up directly I would use my proxy, that would somehow enable Alexa's microphone and switch Alexa into Listening state. When Alexa goes back to Idle the proxy should automatically switch it to Microphone Off state. What I need in general are: The proxy should know Alexa's current state. Won't be the best solution but I may can... voice command to the proxy device. More precisely it should be able to switch Alexa between its following states. Idle: When Alexa is idle, customers can use the Alexa wake word or a physical

  • should used something designed for that purpose? If my understanding is correct, can someone please point me in the direction of a device that I can put in my ceiling and the corresponding wall...Dumb Question about Smart Switches I have been reading about smart switches, this article mentions load control switches (master, should be one per light) and add-on switches (non-load controlling switches). Let's say I want to put the load control switch into the ceiling (hidden) and just use the add-on switches as the 'physical' switches. In the context of a 'dumb light', is my

  • should used something designed for that purpose? If my understanding is correct, can someone please point me in the direction of a device that I can put in my ceiling and the corresponding wall...Dumb Question about Smart Switches I have been reading about smart switches, this article mentions load control switches (master, should be one per light) and add-on switches (non-load controlling switches). Let's say I want to put the load control switch into the ceiling (hidden) and just use the add-on switches as the 'physical' switches. In the context of a 'dumb light', is my

  • I have a Smart Switch (Sonoff Dual WiFi Wireless Smart Switch), and I control it through a Google Home. It works as a contact, like if it was a switch: I want to control an electric blind, that has this connections: The neutral is always connected, and, if you power up "Phase Up" the blind goes up, and if you power up "Phase Down", it goes down. The endstop is located internally of the blind motor. I have another switch, for manual control, with 2 buttons, up and down, and when you click one, the other disconnects automatically, so you can't press both at the same time. Any ideas

  • I have a Smart Switch (Sonoff Dual WiFi Wireless Smart Switch), and I control it through a Google Home. It works as a contact, like if it was a switch: I want to control an electric blind, that has this connections: The neutral is always connected, and, if you power up "Phase Up" the blind goes up, and if you power up "Phase Down", it goes down. The endstop is located internally of the blind motor. I have another switch, for manual control, with 2 buttons, up and down, and when you click one, the other disconnects automatically, so you can't press both at the same time. Any ideas

Data information