now that i understand how my motion sensor, lights, and timer works with HA on my Raspberry Pi, i will proceed with swapping out the codes for using HDMI CEC to power on the TV that’s connected to my Odroid C2. Hopefully this guide https://www.home-assistant.io/components/hdmi_cec/ works.
i have to install HA onto my C2 as well right? i was thinking maybe HA on the rpi will send the command to the C2 to power on the TV. but with my amateur coding skill, it’s probably best to just start over with another install of HA on C2.
The way I have mine set up, is if motion is detected in a room, the lights triggered in that automation will stay on until another motion sensor is triggered in a different room, so my lights follow me around the house. Or the sun rises or I leave the house, or whatever reason.
Thanks, I will be using the light.turn_{{ trigger.to_state.state}}. I wanted to use that method for other automations but couldn’t get it working but your example worked!
I have this weird hype when I use as few lines as possible for automations
- service_template: 'homeassistant.turn_{{trigger.to_state.state}}'
data_template:
entity_id: >
{% set t = trigger.entity_id %}
{% set mapper = {'binary_sensor.computer_room_motion' : 'group.computer_room',
'binary_sensor.living_room_motion' : 'switch.living_room_light',
'binary_sensor.kitchen_motion_sensor' : 'group.kitchen',
'binary_sensor.dining_room_motion_sensor':'group.dining_room',
'binary_sensor.craft_room_motion_sensor': group.craft_room}
%}
{{ mapper[t] if t in mapper else 'light.gateway_light'}}
not sure if the name trigger_entity isnt a bit confusing, too close to the reserved trigger.entity_id, and not much shorter. Better name it t then way shorter…
–edit-- missed a %} in the template above, edited it to be complete.
Well the examples given probably work best and also allow for multiple motion sensors but I currently only have one room light automated. I just used @Mariusthvdb service template so my automation now looks like:
- id: Automatic_kitchen_light
alias: Automatic kitchen light
trigger:
- platform: state
entity_id: binary_sensor.motionsensor_kitchen
to: 'on'
- platform: state
entity_id: binary_sensor.motionsensor_kitchen
to: 'off'
for:
minutes: 1
condition:
condition: and
conditions:
- condition: state
entity_id: group.all_devices
state: 'home'
- condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.motionsensor_kitchen
state: 'on'
- condition: numeric_state
entity_id: sensor.luxsensor_kitchen
below: 100
- condition: state
entity_id: binary_sensor.motionsensor_kitchen
state: 'off'
action:
service_template: >
light.turn_{{ trigger.to_state.state}}
data_template:
transition: 1
entity_id: light.kitchen
for conditions: I need someone to be home because I have pets that trigger motion sensors when no one is home. Also sometimes when the light in the kitchen turns on the light sensor gives a high light value so I need to makes sure it will turn off even with higher light levels. So thats why I have so many conditions.
@touliloup - Thanks for all the feedback provided. Been very helpful.
I’m still new to writing automation routines and have all my routines in the automation.yaml file which totals over 15 now.
When I incorporate the timer bit of code, there is an error in the homeassistant.log file.
ERROR:homeassistant.util.yaml:while parsing a block collection
in "/config/automation.yaml", line 4, column 1
expected <block end>, but found '?'
in "/config/automation.yaml", line 162, column 1
Failed config
General Errors:
- Error loading /config/configuration.yaml: while parsing a block collection
in "/config/automation.yaml", line 4, column 1
expected <block end>, but found '?'
in "/config/automation.yaml", line 162, column 1
Successful config (partial)
Line 4 is the start of the first automation routine that starts with - alias
and line 162 is the timer code timer:
Do you or anyone else have any ideas on how to workaround this error?
I moved the following into a file called timer.yaml
timer:
timer_lamp:
duration: '00:00:25'
The timer.yaml file is found under the config folder along with the configuration.yaml and automation.yaml files.
When looking into the logs since the time light wasn’t turning off after 25 seconds where no motion had been seen within that timeframe, I am seeing an error message of:
2018-11-10 15:31:02 WARNING (MainThread) [homeassistant.core] Unable to find service timer/start
The automation for that is associated with the timer looks like:
- alias: "Motion Detected"
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_158d0001d571ad
to: 'on'
action:
- service: timer.start
entity_id: timer.timer_lamp
- service: light.turn_on
entity_id: light.ge_14294_inwall_smart_dimmer_level
- alias: "Turn off lights at end of timer"
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_lamp
action:
service: light.turn_off
entity_id: light.ge_14294_inwall_smart_dimmer_level
Is there something I need to put in the configuration.yaml file to add a timer component in order to call that in the automation?
Yes that work too. If you want to keep it in a separate file, just look in your config file how you included the automation file and do the same with a timer file.
Hi Code works perfectly just want to add one important condition in my automation.
if switch is manually on (without motion) then it should not turn off after X minutes. Can some one help me how to achieve the same in my existing automation. Below is my code.
alias: Fully automated garden lights
description: ''
trigger:
- platform: state
entity_id: binary_sensor.network_video_recorder_motion_2
to: 'on'
- platform: state
entity_id: binary_sensor.network_video_recorder_motion_2
to: 'off'
for:
hours: 0
minutes: 3
seconds: 0
condition:
- condition: time
after: '18:00:00'
before: '05:30:00'
action:
- service_template: switch.turn_{{ trigger.to_state.state }}
entity_id: switch.sonoff_10010ebac5
mode: single