Bruh multisensor automation

Hello all-

I have a question about automation using the pir sensor. I’m setting up a simple test to start out with, having it turn on a light when motion is detected, but I would like to build it into some sort of theft deterrent system. However, I can’t seem to get HA to recognize the state change from ‘standby’ to ‘motion_detected’, so for the time being I’ve done the reverse, having it trigger based on changing states back to standby. but, like, if a burglar knew this he could just have his buddy wave at it constantly while he loots the place :sushing_face::dizzy_face:

I am using a State trigger:

  - alias: Turn on test light when there is movement
	trigger:
	  platform: state
	  entity_id: sensor.sn1_pir
	  to: 'standby'
	action:
	  service: homeassistant.turn_on
	  entity_id: light.bedroom

In the logbook, I don’t see any evidence of the PIR sensor changing to a ‘motion_detected’ state , how ever I do on the serial monitor in Arduino IDE as well as HA front end. Should I be using an MQTT trigger?

automation:
  trigger:
	platform: mqtt
	topic: living_room/switch/ac
	# Optional
	payload: 'on'

Thank you,
-rev

What shows up in the dev menu for the PIR sensor?

In HA it’s the <> button in the left side menu.

1 Like

I use the following as the trigger::

trigger:
  - platform: state
    entity_id: sensor.sn1_pir
    state: "motion detected"

Seems to work well.

Regarding your action section:

action:
  service: homeassistant.turn_on
  entity_id: light.bedroom

Have you tried:

service: light.turn_on

Hope that helps.

thank you guys, as you both pointed me toward, it was just a simple punctuation error, in this case:

motion_detected

instead of

motion detected

:roll_eyes:

Easy to overlook.

Enjoy!

Can someone guide me on how to control the LED colors when turning on LED?

I use the following code to turn the LED Green when someone is home and motion is detected and then RED if no one is at home. I also change the brightness on the Green so that it is not too bright.

Depending on the value of rgb_color: [0, 255, 0] red.green.blue you can change the shade of each colour.

  alias: Hallway Motion Trigger LED On - Home
  trigger:
    platform: state
    entity_id: sensor.hallway_pir
    from: 'Standby'
    to: 'Motion Detected'
  condition:
   - condition: state
     entity_id: group.family
     state: home
  action:
    service: light.turn_on
    entity_id: light.hallway_led
    data:
      brightness: 20
      rgb_color: [0, 255, 0]


  alias: Hallway Motion Trigger LED On - Not Home
  trigger:
    platform: state
    entity_id: sensor.hallway_pir
    from: 'Standby'
    to: 'Motion Detected'
  condition:
   - condition: state
     entity_id: group.family
     state: not_home
  action:
    service: light.turn_on
    entity_id: light.hallway_led
    data:
      brightness: 250
      rgb_color: [255, 0, 0]

Thank you. Will try that shortly.

I thought I had this working, but now I’m getting an error on line 12 saying “Mapping values are not allowed on line 12.” Any thoughts on how to support multiple conditions? Appears to break on condition: time and “before” statement.

alias: 'Turn On LED on Motion'

trigger:

  • platform: state
    entity_id: sensor.sn2_pir
    to: ‘motion detected’
    condition:
    condition: and
    conditions:
  • condition: template
    value_template: “{{ is_state(‘weather.openweathermap’, ‘rainy’) }}”
  • condition: time
    after: ‘06:30:00’
    before: ‘09:00:00’
    action:
    service: homeassistant.turn_on
    entity_id: light.sn2_led
    data:
    brightness: 50
    rgb_color: [255,0,0]

Can you add formatting to your code so we can check the spacing ? Paste it in then click on </> above.

Also add your log showing the error thrown ?

alias: 'Turn On LED on Motion'

trigger:

  • platform: state
    entity_id: sensor.sn2_pir
    to: ‘motion detected’
    condition:
    condition: and
    conditions:
  • condition: template
    value_template: “{{ is_state(‘weather.openweathermap’, ‘rainy’) }}”
  • condition: time
    after: ‘06:30:00’
    before: ‘09:00:00’
    action:
    service: homeassistant.turn_on
    entity_id: light.sn2_led
    data:
    brightness: 50
    rgb_color: [255,0,0]

There is still no formattIng. Look at my post above 26 days ago - that’s when it is formatted correctedly using </>

Very Sorry – I was clicking on the </>. Will try again.

alias: 'Turn On LED on Motion'
trigger:
  - platform: state
entity_id: sensor.sn2_pir
to: 'motion detected'
condition: 
   condition: and
   conditions:
   - condition: template
 value_template: "{{ is_state('weather.openweathermap', 'rainy') }}"
   - condition: time
    after: '06:30:00'
    before: '09:00:00'
action:
  service: homeassistant.turn_on
  entity_id: light.sn2_led
  data:
  brightness: 50
  rgb_color: [255,0,0]

Error:
2017-12-03 20:59:04 ERROR (SyncWorker_0) [homeassistant.util.yaml] mapping values are not allowed here
in “/config/automation/ShowWeatherLED2.yaml”, line 12, column 14
2017-12-03 20:59:04 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: mapping values are not allowed here
in “/config/automation/ShowWeatherLED2.yaml”, line 12, column 14

Try this

  alias: 'Turn On LED on Motion'
  trigger:
    - platform: state
  entity_id: sensor.sn2_pir
  from: 'standby'
  to: 'motion detected'
  condition: 
    - condition: template
    value_template: "{{ is_state('weather.openweathermap', 'rainy') }}"
    - condition: time
    after: '06:30:00'
    before: '09:00:00'
  action:
    service: homeassistant.turn_on
    entity_id: light.sn2_led
    data:
    brightness: 50
    rgb_color: [255,0,0]
alias: 'Turn On LED on Motion'
trigger:
  - platform: state
entity_id: sensor.sn2_pir
from: 'standby'
to: 'motion detected'
condition: 
    - condition: template
    value_template: "{{ is_state('weather.openweathermap', 'rainy') }}"
    - condition: time
    after: '06:30:00'
    before: '09:00:00'
action:
   service: homeassistant.turn_on
   entity_id: light.sn2_led
   data:
   brightness: 50
   rgb_color: [255,0,0]

I tried your idea (above), and still seeing error after reboot.
2017-12-04 19:00:06 ERROR (SyncWorker_0) [homeassistant.util.yaml] while parsing a block collection
in “/config/automation/ShowWeatherLED2.yaml”, line 8, column 5
expected , but found ‘?’
in “/config/automation/ShowWeatherLED2.yaml”, line 9, column 5
2017-12-04 19:00:06 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while parsing a block collection
in “/config/automation/ShowWeatherLED2.yaml”, line 8, column 5
expected , but found ‘?’
in “/config/automation/ShowWeatherLED2.yaml”, line 9, column 5

Thanks in Advance for your help.

Just trying to do this whilst in work so it could fail on my system as well - no way of checking whilst away from home.

Instead of rebooting and checking for errors run the built in script checker by running this single command from putty or whatever you use to SSH into your pi.

sudo /srv/homeassistant/bin/hass --script
check_config -c /home/homeassistant/.homeassistant

I use it all the time when I make changes as it save a lot of time.

When I get time I will try your automation on my pi.

Thank you very much for your support. I will check my conditions, I think it is because I’m trying to use a value_template and time as conditions.

I appreciate the tips as well. I’m currently running under HASSIO image, but will try and find similar way.

Thanks,
Bryan

alias: 'Turn On LED on Motion'
trigger:
  - platform: state
    entity_id: sensor.sn2_pir
    from: 'standby'
    to: 'motion detected'
condition: 
   condition: and
   conditions:
    - condition: template
      value_template: "{{ is_state('weather.openweathermap', 'rainy') }}"
    - condition: time
      after: '06:30:00'
      before: '09:00:00'
action:
   service: homeassistant.turn_on
   entity_id: light.sn2_led
   data:
       brightness: 50
       rgb_color: [255,0,0]

Finally got above working. Here is working version. Believe my problems were spacing, and conditions statements.
Thank you for your patience, help, and support!

Excellent :grinning: