Created
August 7, 2021 12:14
-
-
Save hnykda/d2df7d3e02a52fa28e6923da183abf7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paho.mqtt.client as mqtt | |
import json | |
client = mqtt.Client() | |
client.username_pw_set("z2muser", "z2pass") | |
client.connect("192.168.0.201", 1883) | |
topic = "zigbee2mqtt/tradfi_alpha/set" | |
from time import sleep | |
def send(message): | |
client.publish(topic, json.dumps(message)) | |
print(message) | |
sleep(2) # sleep is safer here, as it seems that if you don't give time to remote, it will just mess scenes up | |
def _d(scene_id: int, color_temp: int, transition: float = 0.5): | |
d = {"scene_add": { | |
"ID": scene_id, | |
"transition": transition, | |
"color_temp": color_temp, | |
"state": "ON", | |
}} | |
return d | |
send({"scene_remove_all": ""}) | |
sleep(2) # extra sleep to give it time to clean everything up | |
# original is 3 colors only, 1 sec transition, cycles | |
for scene_id, mirred in enumerate(list(range(250, 450, 40)) + [454], 1): | |
send(_d(scene_id, mirred, 0.5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment