Page 1 of 1

Twinkly christmas lights python Script

Posted: Tuesday 10 December 2019 19:18
by djdevil
Hello I need help not knowing how to set up a script for domoticz for my twinkly led lights I found this that is compatible for home assistant and I managed to do it by directly connecting the execution on and off (see photo) I was looking for help on how to update the status of the device when I run this command!
Command of script

https://github.com/joshkay/home-assistant-twinkly

command_on: "python3 /config/python_scripts/twinkly.py TWINKLY_IP_HERE on"
command_off: "python3 /config/python_scripts/twinkly.py TWINKLY_IP_HERE off"
command_state: "python3 /config/python_scripts/twinkly.py TWINKLY_IP_HERE state"

when I run the state command I get 1 or 2 as a print
Then if anyone wants to develop a working plugin, thank you very much :mrgreen:
Immagine.png
Immagine.png (51.13 KiB) Viewed 2234 times

Re: twinkly python Script

Posted: Thursday 12 December 2019 22:27
by djdevil
nobody helping me? :(

Re: twinkly python Script

Posted: Wednesday 18 December 2019 20:10
by xKingx
Found your post looking to switch the miss' Twinkly lights in the tree.

To return the favor, is this what you are looking for?
https://www.domoticz.com/forum/viewtopic.php?t=17993

Re: twinkly python Script

Posted: Wednesday 18 December 2019 21:35
by nl2rma
Thank you djdevil, I was looking for switching twinkly from domoticz and got it working with the information you posted.
Hope someone can help with the status update, I guess is an event that runs the twinkly.py script every minute to get the status and updates the virtual switch

Re: twinkly python Script

Posted: Thursday 19 December 2019 11:59
by djdevil
i done it and all work well

Tutorial:

Code: Select all

# Twinkly Update Light
# Get the data
data=$(python3 /home/pi/domoticz/scripts/twinkly.py YOURIPTWINKLY state)
# Sort it
state=$(echo "$data")


# Load it into Domoticz
curl -s "http://127.0.0.1:80/json.htm?type=command&param=udevice&idx=YOURIDX&nvalue=${state}"
done

Save this like state.sh where you want and done permissions 775


In domoticz create dzevents script like this:

Code: Select all

 return {
        
    on = { timer = {"every 1 minutes"} },
    
	execute = function(domoticz, _)
		os.execute ("/home/pi/domoticz/scripts/state.sh")
	end		

}
let me know if it works well, so let's write a nice tutorial

Re: Twinkly christmas lights python Script

Posted: Thursday 19 December 2019 18:55
by herscotty
I had a problem with the update of my Domoticz device. Every time I set the status of the device twinkly begins from start.
I did a quick and dirty bash script that I pull every minute with crontab:

*/1 * * * * root /home/scott/domoticz/scripts/twinkly.sh status >/dev/null 2>&1

The script twinkly.sh (change your Twinkly IP and Domoticz IDX of your virtual switch)

Code: Select all

#!/bin/bash


case $1 in
on )
        /usr/bin/python3 /home/scott/domoticz/scripts/twinkly.py 192.168.178.136 on
;;
off )
        /usr/bin/python3 /home/scott/domoticz/scripts/twinkly.py 192.168.178.136 off
;;
status )

state_twinkly=$(/usr/bin/python3 /home/scott/domoticz/scripts/twinkly.py 192.168.178.136 state)
#echo "Status twinkly:  $state_twinkly"
state_domoticz=$(curl -s "http://127.0.0.1:8080/json.htm?type=devices&rid=35987" | jq .result[0].Status | sed 's/\"//g')
#echo "echo Domoticz $state_domoticz"

if [ "$state_domoticz" == "On" ]; then
        state_domoticz=1
else
        state_domoticz=0
fi
#echo "echo Domoticz new $state_domoticz"


if [ "$state_twinkly" == "$state_domoticz" ]; then
        exit 0;
else
        curl -s "http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=35987&switchcmd=Toggle"
#       echo "Ă„ndere Status"
fi

;;
esac
In Domoticz self I configure the Switch to trigger the same script:
Action on: "script://twinkly.sh on"
Action off: "script://twinkly.sh off"

If anybody have a question about it let me know or write pm. I hope everyone can use twinkly over Domoticz now :)