Hi,
I’d like to take advantage of the motion detection feature provided by Alexa to trigger an alarm to Alarmo integration.
Alarmo only accepts binary_sensors as triggers.
Alexa motion detection can only be setup with an Alexa routine.
So I’d like to create a script (that, being exposed to Alexa, can be used as action in the Alexa routine), that is activated each time Alexa detects a motion.
This script should simply trigger a binary sensor on for few seconds, so that Alarmo detects an alarm event.
I’ve created a binary_sensor via Helpers, using the template option where the only content is:
auto_off: ‘00:00:10’
see below screenshot:
And I’ve created a script that should trigger that binary_sensor:
alias: ‘MOTION: Alexa motion detected’
sequence:
- event: ‘’
event_data:
action: set_state
entity_id: binary_sensor.alexa_motion_detected
state: Detected
mode: single
… but this is not working
I really appreciate your help
The State template
input box is only for state templates, not other configuration variables. If you want to use advanced features like triggers and auto-off, you need to set the template sensor up in your configuration, not the Helper.
It’s probably not a good idea to set an event listener for an empty string… if nothing else it’s unhelpful if you need to search for it later. I always preface my user-created events with custom_
so they are easily findable when searching config or looking at the list of listeners in the Event tab of Developer Tools.
alias: "MOTION: Alexa motion detected"
sequence:
- event: custom_alexa_motion
event_data:
state: "on"
entity_id: binary_sensor.alexa_motion_detected
Then use a trigger-based template sensor:
template:
- trigger:
- platform: event
event_type: custom_alexa_motion
event_data:
entity_id: binary_sensor.alexa_motion_detected
binary_sensor:
- name: Alexa Motion Detected
state: "{{ trigger.event.data.state }}"
auto_off: "00:00:10"
There are other ways to structure this, depending on how you have connected HA and Alexa. IIRC, HA Cloud can give Alexa access to Input button entities which you could use as the sensor’s trigger instead of a custom event.
In short, I didn’t get one right
As you may have understood, I’m learning and I’m on my first steps … so thank you very much for your patience and support.
Alexa is connected through lamda/AWS. If there is a better way to manage this trigger, I’d like to test it. To be honest I don’t like to keep the Alexa detection routine running 24x7, but I didn’t find a way to do it in another way.
@Didgeridrew forgive my stupid question, but where should I put that code?
I guess that the template code goes to templates.yaml or configuration.yaml
What about the event code?
Is there a better way to achieve same goal?
Yes
The first block of configuration is a Script which can be used as an action in an Alexa routine.
1 Like
@Didgeridrew
Trying to add some complications…
I don’t want the sensor to trigger between 2:00 and 3:00 AM.
I added the following code but it is not working:
- trigger:
- platform: event
event_type: custom_alexa_motion
event_data:
entity_id: binary_sensor.alexa_motion_detected
binary_sensor:
- name: Alexa Motion Detected
state:
value_template: >-
{%if '02.00' < now().strftime('%H.%M') < '03.00' %}
{% else %}
"{{ trigger.event.data.state }}"
{% endif %}
auto_off: "00:00:10"
- trigger:
- platform: event
event_type: custom_alexa_motion
event_data:
entity_id: binary_sensor.alexa_motion_detected
binary_sensor:
- name: Alexa Motion Detected
state:
value_template: >-
{% if now().hour == 2 %}
off
{% else %}
{{ trigger.event.data.state }}
{% endif %}
auto_off: "00:00:10"
Tested but not working too.
I also tested my and your codes in the Developer Tools - Template and they both works.
The “if” part is working, but the binary is not doing what expected.
So I moved the condition to your script code above (post #2) and now it is doing what I expect.
sequence:
- if:
- condition: time
after: "02:30:00"
before: "02:20:00"
then:
- event: custom_alexa_motion
event_data:
state: "on"
entity_id: binary_sensor.alexa_motion_detected
Thank you so much for your prompt reply and help anyway!