trying to configure my first automation on the latest version of HA
I have a physical input from on axis camera - Sate changes as expected in HA
I have a ESP8266 - Relay module, configured and switches ok in HA when toggling.
I want to be able to switch the relay when the axis input is triggered. so far i have tried lots of variations, but this is my config at the minute
- id: one
alias: Turn on relay when camera motion detected
trigger:
- platform: state
entity_id: binary_sensor.workshop_input_0
from: "off"
to: "on"
action:
- platform: switch.turn_on
entity_id: switch.relay1
Formatting of the yaml files is extremely important and things often won’t work if spacing is incorrect. And remember the three components of an automation: trigger (what starts it?); condition (what limitations are there on the trigger?); action (what happens when the trigger event happens?). In your above attempt, it looks like there’s no condition, so I left it out.
Re: the payload values in the switch, I just copied what you had put - you had 1 for on and 2 for off. If off is 0, then obviously change off to 0 in the switch config.
Re: the automation errors, Im really not sure. Does it tell you an error that I can debug?
error log states this -
[homeassistant.config] Invalid config for [automation]: [platform] is an invalid option for [automation]. Check: automation->action->0->platform
Sorry Frank, my mistake. Your automations.yaml should look like this:
- id: one
alias: Turn on relay when camera motion detected
trigger:
- platform: state
entity_id: binary_sensor.workshop_input_0
from: "off"
to: "on"
action:
- service: switch.turn_on
entity_id: switch.relay1
In the “action” stanza I had accidentally put “platform” instead of “service”. It should work now.
cheers thats working. one more question. Would you know how to set it to turn off automatically when the state of the trigger changes, or by setting a time?
I’d create another automation for when the state of the binary_sensor changes to “off”, and add a “for” item, like this:
- id: two
alias: Turn off relay when camera motion not detected for 10 minutes
trigger:
- platform: state
entity_id: binary_sensor.workshop_input_0
to: "off"
for:
minutes: 10
action:
- service: switch.turn_off
entity_id: switch.relay1
Now, with your original automation, the switch will be turned on when motion is detected (the binary sensor goes from off to on); with the second automation, the switch will be turned off when motion is no longer detected (the binary sensor goes to off) for 10 minutes. If motion intervenes during that time, the off automation won’t fire. It will only fire when the binary sensor has an unbroken 10 minute period of “off”.
Keep in mind also that the camera probably has some “dead time” of no motion before actually registering no motion (I.e. Before the Binary sensor switches off). You’ll have to mentally add that to whatever is specified in the off automation (ie if the Binary sensor turns off after 5 mins of no motion, and you specify 10 mins in the off automation,then the light actually won’t turn off for 15 mins of no motion).
Yes fully understood, makes sense doing it that way. I’m well aware how axis cameras operate as well as most other cctv equipment. Been in the trade for 20yrs. So happy to help anybody on that side of things.