Triggers based on Alexa Commands Command/Power On etc

I am struggling with capability to listen to and turn on/off a Boolean value when an alexa command is captured in the house…

I currently have the automaton triggering but it never flips the Boolean value to off

Example YAML for Kitchen Lights - where when I ask Alexa, turn on Kitchen Lights… the trigger fires…
BUT it never flips the value of the boolean

alias: Kitchen - Disable Motion Detection
description: ''
trigger:
  - platform: device
    type: turned_on
    device_id: 71fbed8971cb4db3b020ccf9302926e9
    entity_id: light.kitchen_island_lights
    domain: light
  - platform: event
    event_type: Alexa.PowerController/TurnOn
condition: []
action:
  - service: switch.turn_off
    data: {}
    entity_id: input_boolean.kitchen_motion_detection
mode: single

An input_boolean is not a switch entity, so it will not respond to a switch.turn_off service call. The service you need to call is either homeassistant.turn_off or input_boolean.turn off and you need to use a target, not just entity_id.

alias: Kitchen - Disable Motion Detection
description: ''
trigger:
  - platform: device
    type: turned_on
    device_id: 71fbed8971cb4db3b020ccf9302926e9
    entity_id: light.kitchen_island_lights
    domain: light
  - platform: event
    event_type: Alexa.PowerController/TurnOn
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.kitchen_motion_detection
mode: single
1 Like

Have you any Node-Red experience to convert this to Node-Red flow?

I don’t use Node-Red much, but you should be able to do it with a “Events: All” node configured for the Alexa event and an “Events: State” node for the light entity. Feed both of those into a “Call Service” node…

[{"id":"8363f4cfbc8c2b66","type":"server-events","z":"eef0ebda.2e7498","name":"Alexa Power Controller Event","server":"Home Assistant","version":1,"event_type":"Alexa.PowerController/TurnOn","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":210,"y":460,"wires":[["49b1ff81e2540d32"]]},{"id":"49b1ff81e2540d32","type":"api-call-service","z":"eef0ebda.2e7498","name":"","server":"Home Assistant","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.kitchen_motion_detection","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":500,"y":500,"wires":[[]]},{"id":"3e5c8f40e611e501","type":"server-state-changed","z":"eef0ebda.2e7498","name":"","server":"Home Assistant","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.kitchen_island_lights","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":180,"y":520,"wires":[["49b1ff81e2540d32"],[]]}]

You my friend solved a year long struggle - thank you!
@Didgeridrew

ok I noticed that the way it was added it shows the off state will trigger the boolean change so that is not what we need…

I also noticed that the state is not being detected for alexa commands in node-red…
I will post another question on that in the forum… the automation piece though under HA is working as expected. thank you again

image

That is not the behavior I am seeing.

I played around with this a little last night to get the NR detecting the event… I use the custom skill to connect Alexa to HA, so there may be some differences in the event data if you use another method.

[{"id":"49b1ff81e2540d32","type":"api-call-service","z":"eef0ebda.2e7498","name":"","server":"","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.kitchen_motion_detection","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":560,"wires":[[]]},{"id":"3e5c8f40e611e501","type":"server-state-changed","z":"eef0ebda.2e7498","name":"","server":"","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.kitchen_island_lights","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":200,"y":620,"wires":[["49b1ff81e2540d32"],[]]},{"id":"61cbb8b3f61c77e1","type":"server-events","z":"eef0ebda.2e7498","name":"","server":"","version":1,"event_type":"alexa_smart_home","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"}],"x":170,"y":480,"wires":[["ec933286cee67dd1"]]},{"id":"ec933286cee67dd1","type":"switch","z":"eef0ebda.2e7498","name":"","property":"payload.event.request.namespace","propertyType":"msg","rules":[{"t":"eq","v":"Alexa.PowerController","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":130,"y":560,"wires":[["f0cbbe8795ba0bef"]]},{"id":"f0cbbe8795ba0bef","type":"switch","z":"eef0ebda.2e7498","name":"","property":"payload.event.request.name","propertyType":"msg","rules":[{"t":"eq","v":"TurnOn","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":560,"wires":[["49b1ff81e2540d32"]]}] 

and the HA automation:


alias: Kitchen - Disable Motion Detection
description: ''
trigger:
  - platform: device
    id: device
    type: turned_on
    device_id: 71fbed8971cb4db3b020ccf9302926e9
    entity_id: light.kitchen_island_lights
    domain: light
  - platform: event
    event_type: alexa_smart_home
    event_data:
      request:
        namespace: Alexa.PowerController
condition:
  - "{{ trigger.id == 'device' or trigger.event.data.request.name == 'TurnOn' }}"
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.kitchen_motion_detection
mode: single

You will likely need to add some more conditions to limit it to certain entities being turned on, otherwise it will execute every time any Alexa is ask to turn anything on. For the example above you might try something like:

condition:
  - "{{ trigger.id == 'device' or (trigger.event.data.request.name == 'TurnOn' and trigger.event.data.request.entity_id == 'light.kitchen_island_lights' }}"

For reference, my event information from Developer Tools is as follows:

{
    "event_type": "alexa_smart_home",
    "data": {
        "request": {
            "namespace": "Alexa.PowerController",
            "name": "TurnOn",
            "entity_id": "light.basement_bedroom_2"
        },
        "response": {
            "namespace": "Alexa",
            "name": "Response"
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-12-02T17:12:59.073195+00:00",
    "context": {
        "id": "b84aafd61f61f3be41d963c6c5665fa6",
        "parent_id": null,
        "user_id": "beff28aa371c4d569c40d0b1e0792b05"
    }
}

Thats the problem - see this?

because there is no real (AND) commands here it sees any state change and turns off the detection…
so anytime the island lights turn on or off, the detection turns off…

Maybe I misunderstood what you were trying to accomplish, but I have re-read your comments, and there is no mention of needing an AND…

The “state_changed:light.sitting_room_lights” node will indicate the current state and last_changed time, but by defining an “If State” (equivalent to the “to” in HA automations state triggers)…

(

and selecting the correct output…

the input_boolean.turn_off service will only be called for the change to the “on” state.

That is exactly the behavior I am seeing in my test setup. If you are seeing something different, you may be experiencing interference from other related automations or flows. Also, there isn’t any mechanism in these automations to reset the boolean, so double check that it is being reset between tests.

I believe what we need here we can use via

node-red-contrib-boolean-logic-ultimate

@Didgeridrew - I am re-visiting this again, which custom integration were you using on the HA and Node-Red side?
When you stated - " I use the custom skill to connect Alexa to HA"

I use the Haaska custom skill. On the Node-Red side, I think I was using contrib-alexa-cakebaked but that has since been forked into node-red-contrib-alexa-remote2-applestrudel

1 Like