Twinkly christmas lights python Script

Python and python framework

Moderator: leecollings

Post Reply
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Twinkly christmas lights python Script

Post 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 2231 times
Last edited by djdevil on Thursday 19 December 2019 13:27, edited 1 time in total.
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: twinkly python Script

Post by djdevil »

nobody helping me? :(
xKingx
Posts: 15
Joined: Tuesday 03 June 2014 11:23
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Holland
Contact:

Re: twinkly python Script

Post 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
Raspberry Pi running Domoticz image
User avatar
nl2rma
Posts: 5
Joined: Tuesday 09 February 2016 13:02
Target OS: -
Domoticz version:
Contact:

Re: twinkly python Script

Post 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
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: twinkly python Script

Post 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
herscotty
Posts: 13
Joined: Wednesday 06 May 2015 22:57
Target OS: Linux
Domoticz version: beta
Location: Germany
Contact:

Re: Twinkly christmas lights python Script

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest