Hi Steffen,
You could use a sonoff/smart plug, but then your on/off times will be further delayed. The device would need to boot up and connect to wifi, then your app would need to find the twinkly dwevice, then you could control it.
It isn’t hard to set up.
Copy the twinkly.py script to a location accessable by openhab. If using Raspberry pi/ openhabian / linux, it is likely /var/lib/openhab2 . Finally, ensure you have python3 installed. You probably do if using openhabian.
Next, figure out the IP address of your twinkly device. I logged into my router to do this. If you can reserve that IP address within your router’s system, this may help ensure the IP address doesn’t change in the future.
Then, go to a rule. I use text rules, and can’t give direction to any of the graphical/new interfaces.
You can certainly get much more complicated (and I did a bit), but in the rule you can add:
executeCommandLine("python3 twinkly.py 192.168.0.101 on") // turn the christmas tree on
(replacing the 192.168.0.101 with the IP address of your system)
For myself, I created a summy switch called twinklyTree, and then used the following rule to control the device in a much more ‘normal’ manner elsewhere:
default.items (or whatever .items file you wish, located in openhab’s items directory)
...
Switch twinklyTree "Twinkly Christmas Tree" <light>
yourRules.rules (or whatever .rules file you wish, located in openhabs rules directory. Remember to edit the IP address)
rule "Twinkly Christmas Tree Power State"
when
Item twinklyTree received command
then
if (receivedCommand == ON) {
executeCommandLine("python3 twinkly.py 192.168.0.209 on") // turn the christmas tree on
}
else {
executeCommandLine("python3 twinkly.py 192.168.0.209 off") // turn the christmas tree off
}
end
Finally, I simply toggle the twinklyTree switch in PaperUI, HabPanel, or send a command with twinklyTree.sendCommand(ON) or twinklyTree.sendCommand(OFF).
This should provide a complete and working implementation.
It doesn’t take long at all, you don’t need to buy anything extra (and flash then configure it). Much faster overall. I have several other rules that then turn the tree on or off as needed. I have a simple 433mHz button for the kids to toggle it on / off, and my script to shut everything off at the end of the day turns its lights off. The wake up rule in the morning turns it on.
If you wanted to go above and beyond, you could change the item to be a dimmer instead of a switch, and then send the off command if brightness 0, and otherwise send on and the brightness for all other values - if using Jeroen’s modified twinkly script above.
Edit: updated the rule to use the receivedCommand to reliably use the new command, not the possibly old switch state.