I have an ESP8266 with an IR Receiver that I use to control various items around the office.
I’ve bought a “Wiz” light to play with and have been able to toggle it on/off and increase/decrease the brightness using an IR Remote. The following code is the bit that increases the brightness on a button press.
This works as long as the light is already on. What I’ve not been able to figure out is the Condition statement needed to turn the light on if needed when the “Brightness Increase” button is pressed. I’ve tried several different variations of Conditions but just can’t seem to figure out the correct place to put it or the correct syntax. I’m likely over-thinking/over-complicating this so any help would be appreciated.
Here’s the log showing the following sequence of button presses. Each button press returns two log entries. (State ON/State OFF)
Power Toggle (turn light on)
Increase Brightness
Decrease Brightness
Power Toggle (turn light off)
Increase Brightness (with light off)
Decrease Brightness (with light off0
No errors indicated here. The first four steps work as expected. I believe the issue with trying to change the brightness level when the light is off is I’m getting the current brightness level, adding 10 and setting that as the new level. With the light off we can’t get or set the brightness so the function fails.
[07:19:24][D][binary_sensor:036]: 'Wiz Light Toggle': Sending state ON
[07:19:25][D][binary_sensor:036]: 'Wiz Light Toggle': Sending state OFF
[07:19:30][D][binary_sensor:036]: 'Wiz Light Brighter': Sending state ON
[07:19:30][D][binary_sensor:036]: 'Wiz Light Brighter': Sending state OFF
[07:19:34][D][binary_sensor:036]: 'Wiz Light Dimmer': Sending state ON
[07:19:34][D][binary_sensor:036]: 'Wiz Light Dimmer': Sending state OFF
[07:19:38][D][binary_sensor:036]: 'Wiz Light Toggle': Sending state ON
[07:19:39][D][binary_sensor:036]: 'Wiz Light Toggle': Sending state OFF
[07:19:42][D][binary_sensor:036]: 'Wiz Light Brighter': Sending state ON
[07:19:42][D][binary_sensor:036]: 'Wiz Light Brighter': Sending state OFF
[07:19:46][D][binary_sensor:036]: 'Wiz Light Dimmer': Sending state ON
[07:19:46][D][binary_sensor:036]: 'Wiz Light Dimmer': Sending state OFF
I guess I should have explained this is much more of a learning exercise for me rather than something I’m trying to setup to actually do something. My goal for this was to do everything from the device without needing any HA Automations .
So with that in mind, what are the potential pitfalls of calling the HA Service from a device?
I know ESPHome has it’s own Light Component. I did try to implement this using that but the bulb I have doesn’t support setting the brightness by percentage as the light.dim_relative Action needs. I tried setting up a Template to convert the brightness level to something the bulb can understand but couldn’t get it to work.
Thanks Tom. I think I’m pretty close with your suggestion. I did try several variations of this yesterday with no success. My guess is I don’t have something indented correctly or there’s missing/unneeded ‘-’ in there that’s confusing things. As a side note, can someone explain when a ‘-’ should/shouldn’t be used?
This bit returns the error shown after. What I’m trying here is to first check to see if the light is on. If not, turn it on then continue with setting the brightness. If the light is already on, just set the brightness.
INFO Reading configuration /config/esphome/ir-receiver.yaml...
ERROR Error while reading config: Invalid YAML syntax:
while parsing a block collection
in "/config/esphome/ir-receiver.yaml", line 105, column 7:
- condition:
^
expected <block end>, but found '?'
in "/config/esphome/ir-receiver.yaml", line 109, column 7:
homeassistant.service:
^
I’ve tried moving the indentation around with no luck.
The ESPHome docs show using an ‘if’ statement combined with the ‘condition’ statement. I tried several variations of that with no luck.