Newbie at automation axis camera to switch relay on esp

Hi Folks

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

switch esp:
  platform: mqtt
  name: Relay1
  state_topic: "/van/lounge/sw"
  command_topic: "/van/gpio/16"
  payload_on: "1"
  payload_off: "2"
  qos: 0
  optomistic: false

automations

- action:
  - alias: switch.Relay1
data:
   entity_id: switch.Relay1
service: turn.on
  alias: Input Axis
  condition: []
  id: '1505304420810'
  trigger:
  - entity_id: binary_sensor.workshop_input_0
    from: 'off'
    platform: state
    to: 'on'

Where am i going wrong? thanks in advance

frank

Hey Frank! Looks like a couple of things have gotten jumbled up. Here’s how I would set it up.

In your configuration.yaml:

switch:
  - platform: mqtt
    name: Relay1
    state_topic: "/van/lounge/sw"
    command_topic: "/van/gpio/16"
    payload_on: "1"
    payload_off: "2"
    qos: 0
    optimistic: false

In your automations.yaml:

- 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.

hi

changing the payload values in the switch, stops the relay from switching off payload 0 lets me switch it off.

Ive tried the automation config you suggested but it bombs out with errors on line 3 and 8, any ideas?

Cheers

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?

apologies, typo on my part.

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?

thanks again for your help

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).

Hopefully I’m explaining that clearly.

Superb cheers.

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.

Thanks again for all your help

1 Like

No problem, enjoy!

It’s is configurable but default is to go to off immediately after motion has stopped.