Not starting an automation if lights were turned on by Google Home?

Here’s hoping someone can assist. I have an automation that turns lights on based on motion or vibration (with a lux sensor in there too).

Is there a way to not trigger the automation if the lights were manually turned on by my Google Home?

According to the logbook, I can see when the lights have been turned on/off by Google Home, but I dont know how to get it to be a condition of the automation.

The automation (blueprint) looks like this:

blueprint:
  name: Vibration-activated Light with illuminance
  description: Turn on a light when vibration is detected and illuminance is below a
    set Lux level.
  domain: automation
  input:
    vibration_entity:
      name: vibration Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: vibration
          multiple: false
    lux_entity:
      name: Illuminance Sensor
      selector:
        entity:
          domain: sensor
          device_class: illuminance
          multiple: false
    lux_level:
      name: Illuminance level
      description: If lux is below this value and vibration is detected, the light will
        turn on.
      default: 100
      selector:
        number:
          min: 0.0
          max: 1000.0
          step: 1.0
          mode: slider
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    no_vibration_wait:
      name: Wait time
      description: Time to leave the light on after last vibration is detected.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          step: 1.0
          mode: slider
    brightness:
      name: Light brightness
      description: The brightness of the lights.
      default: 254
      selector:
        number:
          min: 5.0
          max: 255.0
          step: 1.0
          mode: slider

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input 'vibration_entity'
  from: 'off'
  to: 'on'

condition:
  condition: and
  conditions:
  - condition: numeric_state
    entity_id: !input 'lux_entity'
    below: !input 'lux_level'


action:
- service: light.turn_on
  data:
    brightness: !input 'brightness'
  target: !input 'light_target'
- wait_for_trigger:
    platform: state
    entity_id: !input 'vibration_entity'
    from: 'on'
    to: 'off'
- delay: !input 'no_vibration_wait'
- service: light.turn_off
  target: !input 'light_target'

I had thought a value template would be a solution, but I’m not sure how to go about it.

Nice question. Have same. Something like:
If triggered by ‘integration’ id or name

Would be nice to have this for many other automations

In my head it sounds so simple:

- condition: template
    value_template: '{{ target.to_state.context.user_id != Goggle Home }}'

But it doesnt like ‘target’ in the template. I’m stumped.

if every integration get its own user.id then this seems a idea :slight_smile:

Maybe try tinker around with:

trigger.to_state.context.user_id

User_id seems to be valid:

And here you see something similar - that might be worth a try:

From what I understand that value template looks for the change in state of the ‘trigger’, in my case that is the vibration sensor.

I need the condtion to check the last change state of the lights.

Probably the “long road arround the problem” will be the easy one.

Create a new automation, triggered by on light on. Check the user for the light-on statement. If it is Google Home, set a Helper to on, and then use tis helper as a condition in you automation.

Alright, I think we’re on to something.

I’ve setup boolean switches that trigger if GH turns the lights and off.

But the blueprint is giving me grief. The blueprint so far is:

blueprint:
  name: TESTING
  description: Turn on a light when motion is detected and illuminance is below a
    set Lux level.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
          multiple: false
    lux_entity:
      name: Illuminance Sensor
      selector:
        entity:
          domain: sensor
          device_class: illuminance
          multiple: false
    lux_level:
      name: Illuminance level
      description: If lux is below this value and motion is detected, the light will
        turn on.
      default: 100
      selector:
        number:
          min: 0.0
          max: 1000.0
          step: 1.0
          mode: slider
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          step: 1.0
          mode: slider
    brightness:
      name: Light brightness
      description: The brightness of the lights.
      default: 254
      selector:
        number:
          min: 5.0
          max: 255.0
          step: 1.0
          mode: slider
    input_boolean:
        name: Boolean
        description: The boolean to check before automation is run
        selector:
          target:

mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input 'motion_entity'
  from: 'off'
  to: 'on'

condition:
  condition: and
  conditions:
  - condition: numeric_state
    entity_id: !input 'lux_entity'
    below: !input 'lux_level'
  - condition: state
    entity_id: !input 'input_boolean'
    state: 'off'

action:
- service: light.turn_on
  data:
    brightness: !input 'brightness'
  target: !input 'light_target'
- wait_for_trigger:
    platform: state
    entity_id: !input 'motion_entity'
    from: 'on'
    to: 'off'
- delay: !input 'no_motion_wait'
- service: light.turn_off
  target: !input 'light_target'

and I get an error of:

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:651
Integration: Automation (documentation, issues)
First occurred: 4:47:09 PM (1 occurrences)
Last logged: 4:47:09 PM

Blueprint TESTING generated invalid automation with inputs OrderedDict([('motion_entity', 'binary_sensor.lumi_lumi_sensor_motion_aq2_21c4bc07_ias_zone'), ('lux_entity', 'sensor.lumi_lumi_sensor_motion_aq2_21c4bc07_illuminance'), ('light_target', OrderedDict([('entity_id', 'light.upstairs_zha_group_0x0002')])), ('input_boolean', OrderedDict([('entity_id', 'input_boolean.upstairs')]))]): Entity entity_id is neither a valid entity ID nor a valid UUID for dictionary value @ data['condition'][0]['conditions'][1]['entity_id']. Got None

What am I missing?

My YAML skills are not sufficient to figure out what’s wrong. It looks good for me.

However, you blueprint logic is a little sub-optimal, if you ask me. It will wait for no-motion and then it will do a delay before turning off. If someone enteres into the room again, it will re-trigger. With this simple turn on/off it will work, as it will just turn on the light again. However if you have transistions of light etc, it will re-trigger and this will be visible.

I normally use the “for-time” in the trigger, to secure that it have been “off” for a given time. Looking like this.

trigger:
  - platform: state
    entity_id: group.badmotion
    to: 'off'
    for:
      hours: 0
      minutes: 8
      seconds: 0
1 Like

AHA! It seems that using ‘input_boolean’ or ‘boolean’ in the input section of the blueprint upset it. Once I changed it go ‘GH’ it is working with no errors.