Alexa as a trigger

Hi,
Is there any way of HA detecting when I’ve asked Alexa to turn the lights on?

On my current set up I have an input_boolean set up for each room. If motion is detected and the input_boolean is set to “off” then it turns the lights on/off according to the motion. If I turn the dimmer switch, or some other device (such as the TV in the living room) on, then it set’s the input_boolean to “on”, therefore bypassing the motion sensor rule. This is useful in the living room because I tend to sit still for long enough the lights go out if they’re completely controlled by the motion sensor rules, so having the TV keep the light on works well.

I also want to add a rule that turns the input_boolean on when I tell alexa to turn the lights on. e.g.

trigger:
  platform: state
  entity_id: light.living_room
  to: 'on'
condition:
  ALEXA TURNED IT ON
action:
  - service: input_boolean.turn_on
    data:
      entity_id: input_boolean.living_room

Is this possible?

I don’t think using Emulated Hue that there is any way to figure out that Alexa turned the light on rather than you. You could do this with intents though, have Alexa run a script that turns the light on and flips the boolean.

1 Like

Took me a while getting intents setup, but now I have I have realised that I’d have to ask Alexa “Alexa, tell Home Assistant to turn the living room lights on.” which is a bit annoying. Emulated Hue removes that. Hm I guess there is no other way!

There isn’t - I use intents too because of the flexibility it gives you.

I use Haask instead of Emulated Hue which uses intents. I think BRUH has a video to help set it up.

You can use both, though. Emulated_hue for the things you want simple on/off control of, intents for the rest.

Nice! with this can i make alexa to say more think and not only Trun on/off?

i did it this way.

  • use emulated hue
  • create an input boolean (or an input slider, but then you need to work on emulated hue itselve) for every command you want Alexa to make.
  • use appdaemon
  • if Alexa turns on her own input boolean let appdaemon turn on anything you like.

i have made it so that homeassistant tells me that Alexa turned on the lights.
i also let homeassistant tell me that the lights are turned on by a remote, or when homeassistant itself turns on the lights.

I warn that haask is a lot more work (SSL/ Amazon dev account/ setup instructions) to setup that emulated hue but adds functionality. You can turn on more stuff with more commands.

Turn on these things:

Groups
Input Booleans
Lights
Locks
Media Players
Scenes
Scripts
Switches

Usage

To do this… Say this…
ON Commands
Alexa, turn on
Alexa, start
Alexa, unlock
Alexa, open
Alexa, boot up
Alexa, run
Alexa, arm
OFF Commands
Alexa, turn off
Alexa, stop (this one is tricky to get right)
Alexa, stop running (also very tricky)
Alexa, lock
Alexa, close
Alexa, shutdown
Alexa, shut
Alexa, disarm
DIM Commands is a percentage or a number 1-10
Alexa, brighten to
Alexa, dim to
Alexa, raise to
Alexa, lower to
Alexa, set to
Alexa, turn up to
Alexa, turn down to

all the same things can be done with emulated hue, appdaemon and a few extra input booleans.

and you dont need a dev account or try to understand anything from SSL.
i tried other ways, but because i know a little python, that way was more easy and more HA like :wink:

This sounds ideal. Problem is I have no idea what to do with AppDaemon. I have installed it but that’s about as far as I have got. Would you be able to post an example script of what you suggested around Alexa and input booleans? Should be enough to get me started if you would be so kind?

this is an app for Alexa i made:

###########################################################################################
#                                                                                         #
#  Rene Tode ( [email protected] )                                                            #
#  ( with a lot off help from andrew cockburn (aimc) )                                    #
#  2016/3/18 Germany                                                                      #
#                                                                                         #
###########################################################################################

import appdaemon.appapi as appapi
import datetime
import time

class alexa(appapi.AppDaemon):

  def initialize(self):
    self.sound = self.get_app("soundfunctions")
    self.listen_state(self.alexa1,"input_boolean.alexa1")        
    self.listen_state(self.alexa2,"input_boolean.alexa2")        
    self.listen_state(self.alexa3,"input_boolean.alexa3")        
    self.listen_state(self.alexa4,"input_boolean.alexa4")        
    self.listen_state(self.alexa5,"input_boolean.alexa5")        
    self.listen_state(self.alexahkverwarming,"input_slider.woonkamerheizung")        
    self.listen_state(self.alexakkverwarming,"input_slider.keukenheizung")        

  def alexa1(self, entity, attribute, old, new, kwargs):
    if new != "on":
      speaktext = "Alexa heeft alle verlichting uitgedaan"
      self.turn_off("input_boolean.allesuit")
      self.turn_on("input_boolean.alexa1")
      self.sound.say(speaktext,"nl","1")

  def alexa2(self, entity, attribute, old, new, kwargs):
    if new == "on":
      speaktext = "Alexa heeft de woonkamer verlichting aangedaan"
      self.turn_on("switch.hbank")
      self.turn_on("switch.hboog")
      self.turn_on("switch.hrozenhoek")
      self.turn_on("switch.hkachel")
    else:
      speaktext = "Alexa heeft de woonkamer verlichting uitgedaan"
      self.turn_off("switch.hbank")
      self.turn_off("switch.hboog")
      self.turn_off("switch.hrozenhoek")
      self.turn_off("switch.hkachel")
    self.sound.say(speaktext,"nl","1")

  def alexa3(self, entity, attribute, old, new, kwargs):
    if new == "on":
      speaktext = "Alexa heeft de eetkamer verlichting aangedaan"
      self.turn_on("switch.epchoek")
      self.turn_on("switch.eraamhoek")
      self.turn_on("switch.ewandmeubel")
    else:
      speaktext = "Alexa heeft de eetkamer verlichting uitgedaan"
      self.turn_off("switch.epchoek")
      self.turn_off("switch.eraamhoek")
      self.turn_off("switch.ewandmeubel")
    self.sound.say(speaktext,"nl","1")

  def alexa4(self, entity, attribute, old, new, kwargs):
    if new == "on":
      speaktext = "Alexa heeft de verlichting in de gang aangedaan"
      self.turn_on("light.vitrine_in_de_gang")
    else:
      speaktext = "Alexa heeft de verlichting in de gang uitgedaan"
      self.turn_off("light.vitrine_in_de_gang")
    self.sound.say(speaktext,"nl","1")

  def alexa5(self, entity, attribute, old, new, kwargs):
    if new == "on":
      temper = str(self.get_state("sensor.huiskamer_box_4_1"))
      speaktext = "De temperatuur in de woonkamer is nu " + temper + " graden"
      self.turn_off("input_boolean.alexa5")
      self.sound.say(speaktext,"nl","1")

  def alexahkverwarming(self, entity, attribute, old, new, kwargs):
    self.call_service("input_slider/select_value", entity_id="input_slider.huiskamerthermostaata",value=float(new))
    self.call_service("input_slider/select_value", entity_id="input_slider.huiskamerthermostaatb",value=float(new)-1)
    speaktext = "Alexa heeft de thermostaat van de woonkamer op " + new + " graden gesteld"
    self.sound.say(speaktext,"nl","1")

  def alexakkverwarming(self, entity, attribute, old, new, kwargs):
    self.call_service("input_slider/select_value", entity_id="input_slider.keukenthermostaata",value=float(new))
    self.call_service("input_slider/select_value", entity_id="input_slider.keukenthermostaatb",value=float(new)-1)
    speaktext = "Alexa heeft de thermostaat van de keuken op " + new + " graden gesteld"
    self.sound.say(speaktext,"nl","1")

in my customize.yaml i have this:

    input_slider.keukenheizung:
      emulated_hue: true
      emulated_hue_name: "heizung kueche"
    input_slider.woonkamerheizung:
      emulated_hue: true
      emulated_hue_name: "heizung wohnzimmer"

    input_boolean.alexa1:
      emulated_hue: true
      emulated_hue_name: "alle beleuchtung"
    input_boolean.alexa2:
      emulated_hue: true
      emulated_hue_name: "lampe wohnzimmer"
    input_boolean.alexa3:
      emulated_hue: true
      emulated_hue_name: "lampe esszimmer"
    input_boolean.alexa4:
      emulated_hue: true
      emulated_hue_name: "lampe flur"
    input_boolean.alexa5:
      emulated_hue: true
      emulated_hue_name: "temperatur"

as you see i have created some input_booleans before that.
forget about the input slider, it is possible but you have to change the emulated hue code for that.

where i use self.sound.say you could use a notify or a service call to a TTS in HA

there is a lot of dutch and german in there, but the dutch is spoken text and the german what i say to Alexa :wink:

hope this helps.

1 Like

Found this thread looking for information for another problem: so are you saying that input_slider isn’t gonna work with the emulated Hue? Mine will see the device but keeps telling me it isn’t responding when I try to change the brightness. (I’m fine with that if so, just don’t want to keep banging my head on a brick wall if this is the case. :))