I have created a helper in HA where when I trigger it an Alexa routine runs to turn on some lights which are only controlled by Alexa (not exposed to HA directly due to the Bluetooth protocol). It works great. Issue is if someone turns on the lights through Alexa voice how do I update the helper so my dashboard updates in HA too ?
You’ll need to link it using the binary_sensor and input_boolean helper method. Tie the binary_sensor to the input_boolean, something like this -
{{ is_state('input_boolean.bluetooth_light', 'on') }}
Basically, similar logic to how you can integrate a dumb device into HA and make it “smart”. Create an automation and use the states of the binary_sensor with trigger ID’s as your triggers for on and off. Use choose blocks with triggered by conditions to toggle the input_booleans. Share the binary_sensor and input_boolean as entities to your Alexa ecosystem. Create two routines that mirror the HA automation (one for light on, one for light off), but include the actual bluetooth lights in the actions with the input_boolean. This is about as close to “in-sync” as you’ll be able to get between HA and Alexa’s ecosystem. The way I just explained it, you would use Alexa to activate the input_boolean, not the actual bluetooth light. Tweak it to your use-case and liking.
Thanks. I’m not sure I 100% follow. When I turn on the light with Alexa using my voice how is the “kitchen light” linked to the input_boolean or binary_sensor ?
It’s linked through redundancy between the helpers, the HA automation, and the Alexa routines.
Here’s an example, a little different, but essentially the same. I have a moon lamp in my kid’s room for a night light. It’s a dumb device controlled via IR remote. I programmed the IR signals into HA and created this automation. Then, I shared the helpers to Alexa and created routines just like I explained, one for moon lamp on, one for moon lamp off. That way, when I use Alexa voice to turn it on or off, it shows correctly in HA
alias: Appliance - Moon Lamp
description: ""
mode: single
triggers:
- entity_id:
- binary_sensor.moon_lamp
id: moon_lamp_on
to: "on"
trigger: state
- entity_id:
- binary_sensor.moon_lamp
to: "off"
id: moon_lamp_off
trigger: state
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- moon_lamp_on
sequence:
- target:
entity_id: remote.ur_broadlink_1
data:
num_repeats: 1
delay_secs: 0.4
hold_secs: 0
device: Moon Lamp
command: Power On
action: remote.send_command
- metadata: {}
data: {}
target:
entity_id: input_boolean.moon_lamp
action: input_boolean.turn_on
- conditions:
- condition: trigger
id:
- moon_lamp_off
sequence:
- target:
entity_id: remote.ur_broadlink_1
data:
num_repeats: 1
delay_secs: 0.4
hold_secs: 0
device: Moon Lamp
command: Power Off
action: remote.send_command
- data: {}
target:
entity_id: input_boolean.moon_lamp
action: input_boolean.turn_off
And again, you won’t use Alexa voice to turn on/off the light anymore. I recommend you change the name of the light. You’ll use Alexa voice to turn on/off the input_boolean instead. You’ll add the light being turned on/off to the actions of your Alexa routines.
edit To dispel any confusion regarding the binary_sensor. It is a template sensor helper and the snippet of code I shared in my first comment is what you’ll need to add to the state field of the template sensor, just make sure you use the correct name of your input_boolean sensor in it.
OK that makes sense. The lights do not work with HA only Alexa so do I actually need the binary_sensor ? If I rename the light on Alexa to something obscure and then name the input_boolean in HA to the previous name of the light and then expose it to Alexa. Would this then work when I say Alexa turn on the kitchen light which is actually the input_boolean which will trigger the Alexa routine and at the same time it will update in HA ?
Excellent question. Yes, do it exactly as I explained. Alexa routines are fickle b*stards when using input_booleans as triggers. You’re welcome to try it, but I can almost guarantee with 100% certainty that it won’t work. I’ve been there and done that lol.