Lighting automation woes

Hi,

I am having some issues with my lighting automations. I have read of cases of using the service: light.turn_on and the service: homeassistant.turn_on

Which one should I use? I have tried bot and neither work for me.

Here is an example of my automation:

- alias: Turn on Upstairs Hallway lights when there is movement after sunset
  trigger:
    platform: state
    entity_id: binary_sensor.aeotec_zw074_multisensor_gen5_sensor_4_0
    to: 'on'
  condition:
    condition: sun
    after: sunset
  action:
    service: homeassistant.turn_on
    entity_id: light.upstairs_passage

- alias: Turn on Upstairs Hallway lights when there is movement before sunrise
  trigger:
    platform: state
    entity_id: binary_sensor.aeotec_zw074_multisensor_gen5_sensor_4_0
    to: 'on'
  condition:
    condition: sun
    before: sunrise
  action:
    service: homeassistant.turn_on
    entity_id: light.upstairs_passage

- alias: Turn off Upstairs Hallway lights 10 minutes after last movement
  trigger:
    platform: state
    entity_id: binary_sensor.aeotec_zw074_multisensor_gen5_sensor_4_0
    to: 'off'
    for:
      minutes: 10
  action:
    service: homeassistant.turn_off
    entity_id: light.upstairs_passage

Note that light.upstairs_passage is a hue group. should this make a difference?

Can someone help?

Thanks

I have another automation that I am trying which is also not working with the following code

- alias: Turn on Kitchen lights when there is movement after sunset
  trigger:
    platform: state
    entity_id: binary_sensor.aeotec_zw074_multisensor_gen5_sensor_2_0
    to: 'on'
  condition:
    condition: sun
    after: sunset
  action:
    service: homeassistant.turn_on
    entity_id: light.fibaro_system_fgd212_dimmer_2_level_7_0

- alias: Turn on Kitchen lights when there is movement before sunrise
  trigger:
    platform: state
    entity_id: binary_sensor.aeotec_zw074_multisensor_gen5_sensor_2_0
    to: 'on'
  condition:
    condition: sun
    before: sunrise
  action:
    service: homeassistant.turn_on
    entity_id: light.fibaro_system_fgd212_dimmer_2_level_7_0

- alias: Turn off Kitchen lights 10 minutes after last movement
  trigger:
    platform: state
    entity_id: binary_sensor.aeotec_zw074_multisensor_gen5_sensor_2_0
    to: 'off'
    for:
      minutes: 10
  action:
    service: homeassistant.turn_off
    entity_id: light.fibaro_system_fgd212_dimmer_2_level_7_0

Light and Switch are two different services and it is important to use the right one. But you may have groups that combine both… so the homeassistant.turn_on/off is the solution as it works for all device types.

I know people who use the homeassistant service only; and some that try to be more specific. I suspect that behind the homeassistant service it figures out the type and uses the right service…

1 Like

Thanks for the reply. I saw the distinction when calling a group entity comprising many sensors including light as opposed to the light entity directly itself.

I am however calling either the light or hue group of lights in both scenarios and neither homeassistant or light as the command seem to work.

Any ideas around my config where I could be tripping up?

Thanks again for any help,

Shouldn’t you be using the service

  - service: light.turn_on

like I have in mine below? light.bathroom is a hue group but I also have 1 at night that use an individual light entity_id: light.bathroom_3

alias: Bathroom lights on motion
trigger:
  - platform: state
    entity_id: binary_sensor.bathroom_sensor_5_0
#    from: 'off'
    to: 'on'
condition:
  condition: and
  conditions:
  - condition: time
    after: '06:00:00'
    before: '01:00:00'
  - condition: numeric_state
    entity_id: sensor.bathroom_luminance_5_3
    below: 8
action:
  - service: light.turn_on
    entity_id: light.bathroom
    data:
      brightness: 255

I have tried both and neither seem to work,… :frowning:

Here are the automations I use with the homeassistant.turn_on service using groups of LIFX bulbs and z-wave motion sensors.


- alias: Office Lights Motion (On)
  trigger:
    platform: state
    entity_id: binary_sensor.ecolink_pir_motion_sensor_sensor_2_0
    to: 'on'
  condition: 
    condition: time
    after: '07:30'
    before: '23:30'
  action:
    service: homeassistant.turn_on
    entity_id: group.office_lights
    data: 
      transition: 15


- alias: Office Lights Motion (Off)
  trigger:
    - platform: state
      entity_id: binary_sensor.ecolink_pir_motion_sensor_sensor_2_0
      to: 'off'
      for:
        minutes: 15
  action:
    - service: homeassistant.turn_off
      entity_id: group.office_lights
      data: 
        transition: 160

like this they stay on for 15 minutes?

Why not keep that value, like 2 minutes. If you are still inside after 2 minutes the first automation will trigger it again, or?

I may reduce it from 15 minutes once I determine the best location to mount my sensor. However, 15 minutes seems pretty good for now.

have you tried the double sensor on top of door that is “counting” the people going in and out?

I’m a bit late to the party, but just wanted to answer this part:

I would suggest that you use the services developer tool (the remote control looking one) to see what works best for you.

In the service data field you can set parameters like this:

{"entity_id":"light.upstairs_passage","rgb_color":[100,150,255]}

Some values need to be in quotes and some don’t, but it’s easier to experiment here than by modifying an automation.