Page 1 of 1

Tplink KL60 - dimmer script

Posted: Sunday 05 June 2022 17:01
by sebw
Hi all,

I'm a new Domoticz user (coming from Home Assistant) and have a dimmable filament lightbulb from Tplink (model KL60). I have found some neat plugins for TPlink HS100 and HS110 but nothing for KL60...

I discovered it's possible to call custom scripts on dummy switches, and there's this nice pyHS100 Python library that can manage the lighbulb so I came up with this bit of code to turn on the lightbulb:

Code: Select all

#!/usr/bin/env python3

import json
import socket
import logging
import pyHS100 as p

ip = "lightbulb.example.org"

logging.info("Trying connection with Smart Bulb " + ip)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, int(9999)))
s.shutdown(2)
bulb = p.SmartBulb(ip)
bulb.turn_on()
It just works, I can turn on and off with bulb.turn_on()or bulb.turn_off() functions.

Now I'm trying to change the virtual switch to switch type "dimmer".
2022-06-05_165910.png
2022-06-05_165910.png (43.34 KiB) Viewed 172 times
Now I see the "on action" script is called anytime I move the slider in the GUI:
2022-06-05 16:55:12.856 Status: User: Admin (IP: x.x.x.x) initiated a switch command (73/Lightbulb Office/Set Level)
2022-06-05 16:55:13.076 Status: Executing script: /opt/domoticz/userdata/scripts/domoticz-kl60/bulb-on.py
Is domoticz somehow passing the level to the "on action" script or I need to use a different way?

In the pyHS100, I can set the brightness of the bulb with this function:

Code: Select all

bulb.brightness = <0-100>
Thanks!
sebw