griffinburkhardt and jedcred,
I have been working on this too. I have used the example provided by griffinburkhardt and various places around the internet to produce a custom component that is working for me. A warning: I have no experience with python. This is literally the first python project I have ever worked on beyond one other basic find and replace script. Treat it as insecure poorly written garbage.
These files create a custom service that adjusts the hard-coded IP addresses to a specific brightness. I do not yet have the skill to read the entities without hard coding them.
These files need to be placed in the config/custom_components/offbright folder that you will create:
manifest.json
{
"domain": "offbright",
"name": "TP-Link OffBright Service",
"documentation": "https://developers.home-assistant.io/docs/dev_101_services",
"requirements": ["python-kasa==0.5.0"],
"dependencies": ["tplink"],
"codeowners": ["@xdraconis", "@griffinburkhardt"],
"iot_class": "local_push",
"version": "0.1.0"
}
__init__.py
import asyncio
from kasa import SmartDimmer
DOMAIN = "offbright"
DEVICES = ["192.168.10.128", "192.168.10.148"]
# Sets the brightness of the selected device
async def set_brightness(device, brightness: int):
await device.update()
await device.set_brightness(brightness)
await device.update()
async def set_offbright(call):
"""Handle the service call."""
brightness = call.data.get("brightness", 0)
await asyncio.gather(*[asyncio.create_task(set_brightness(SmartDimmer(dev), brightness)) for dev in DEVICES])
def setup(hass, config):
"""Set up is called when Home Assistant is loading our component."""
hass.services.register(DOMAIN, "offbright", set_offbright)
# Return boolean to indicate that initialization was successful.
return True
services.yaml
offbright:
name: OffBright
description: Sets the brightness without turning on the lights.
# target:
# entity:
# integration: tplink
# domain: light
fields:
brightness:
description: The percent brightness to set the lights to (0-100%)
example: 100
default: 100
required: true
selector:
number:
min: 1
step: 1
max: 100
unit_of_measurement: "%"
After you add the files, you need to restart and then add ths to your configuration.yaml, and then restart again.
offbright: