Hi,
I have a binary sensor (motion sensor). It changes state when it detects movement (to “on”). I have an automation that runs to send notification to Telegram, and then resets the state of the sensor so it’s ready for the next motion detected. That works fine!
However, every time HA restarts it triggers this automation so I get a false alert. When more sensors are added they’ll probably all send a notification.
So, I’ve set the motion sensor automation to be “False” for initial_state.
Then I wrote a script to enable this automation at startup. The state changes as shown in the Front-End indicating the automation is enabled, but it doesn’t run. Although the state of the binary sensor changes state to “on” when motion is detected it doesn’t trigger the automation to send a Telegram message. Nothing is recorded in logbook. Yet the states in the front-end are as I would expect.
Any ideas?
automation:
- alias: system_start
trigger:
platform: homeassistant
event: start
action:- delay:
seconds: 10 - service: shell_command.startup
- delay:
- alias: motionsensor1automation
initial_state: ‘off’
trigger:
platform: state
entity_id: binary_sensor.motionsensor1
to: ‘on’
action:- service: notify.telegramdevice1
data_template:
title: “Sensor 1 Movement”
message: “Movement detected on Sensor 1” - service: shell_command.resetmotionsensor1
- service: notify.telegramdevice1
shell_command:
resetmotionsensor1: ‘bash /home/homeassistant/.homeassistant/resetmotionsensor1.sh’
startup: ‘bash /home/homeassistant/.homeassistant/startup.sh’
These are the shell scripts:
startup.sh:
#! /bin/bash
curl -X POST -H “x-ha-access: APIPASSWORD”
-H “Content-Type: application/json”
-d ‘{“state”: “off”, “attributes”: {“friendly_name”: “Motion Sensor 1”}}’
http://IPADDRESS:8123/api/states/binary_sensor.motionsensor1
curl -X POST -H “x-ha-access: APIPASSWORD”
-H “Content-Type: application/json”
-d ‘{“state”: “on”, “attributes”: {“friendly_name”: “Motion Sensor 1 Automation”}}’
http://IPADDRESS:8123/api/states/automation.motionsensor1automation
resetmotionsensor1.sh
#! /bin/bash
curl -X POST -H “x-ha-access: APIPASSWORD”
-H “Content-Type: application/json”
-d ‘{“state”: “off”, “attributes”: {“friendly_name”: “Motion Sensor 1”}}’
http://IPADDRESS:8123/api/states/binary_sensor.motionsensor1