This works great except that the lights need to be on before they are dimmed which can get quite jarring at night. I’ve worked out that, with the shellys, I can use the RESTful API to change the brightness, even when the light is off.
So I’m trying to build a little automation to do that. I think I’ve got the templating right based on the template editor but I cannot get it to work. In essence, I am calling the rest service for each light that is not on and updating the brightness based on the ciracdian brightness sensor. Since the REST service needs an IP address, I have a dict with the IP addresses mapped to the entity_id in HA.
When I try and save this, I get the following error: message malformed: expected dictionary @ data['action'][0]
This is the code for the automation. Any thoughts welcome!
I’m guessing it has something to do with having templating within action instead of service / data but not sure how else to do this as I need multiple actions and I won’t know how many until the script runs.
When you use a for loop, you need to use namespace to extract the returned values out of the loop. The method shown above prints something that looks kind of like a list, but it isn’t one functionally.
For the example above it would look something like the following:
if you are using the shellys, the if/then/else allows the brightness to be set for the shelly even when they are turned off. Super useful for those bathroom / bedroom lights not coming on too bright at night!