Controlling Wiz RGBW Smart lightbulbs from Godot 4

Channel:
Subscribers:
694
Published on ● Video Link: https://www.youtube.com/watch?v=SEbsYTw1rY8



Duration: 1:20
505 views
17


Source for research:
https://github.com/sbidy/pywizlight

Here's a quick code dump so you can play with it:
```
extends Node

var INTERVAL = 0.1 # seconds
const PORT = 38899
const ADDRESS = [ # list the IP addresses of your lights or broadcast to all (less reliable, hogs the network)
# "192.168.0.255", # need to do peer.set_broadcast_enabled(true) before using this
"192.168.0.16",
"192.168.0.17",
"192.168.0.18",
]
@onready var peer = PacketPeerUDP.new()

func wiz_broadcast(data:String):
for address in ADDRESS:
peer.set_dest_address(address, PORT)
peer.put_packet(data.to_ascii_buffer())
peer.close()

# Called when the node enters the scene tree for the first time.
func _ready():
while true:
wiz_broadcast('{"method": "setPilot", "params": {"temp": ' + str(randi_range(1000, 10000)) + '}}') # set white of random color temperature (in Kelvin)
await get_tree().create_timer(INTERVAL).timeout
wiz_broadcast('{"method": "setPilot", "params": {"dimming": 10}}') # min
await get_tree().create_timer(INTERVAL).timeout
wiz_broadcast('{"method": "setPilot", "params": {"dimming": 100}}') # max
await get_tree().create_timer(INTERVAL * 2).timeout
wiz_broadcast('{"method": "setPilot", "params": {"r": 0}}') # set an arbitrary RGB color
wiz_broadcast('{"method": "setPilot", "params": {"g": 255}}')
wiz_broadcast('{"method": "setPilot", "params": {"b": 255}}')
await get_tree().create_timer(INTERVAL * 4).timeout
wiz_broadcast('{"method": "setPilot", "params": {"state": false}}') # turn off
await get_tree().create_timer(INTERVAL * 4).timeout
```