Execute any service (turn on switch/light/scene/scripts etc., even run another automation) based on any entity's state change (motion sensor, illuminance, sun rise/set)

Unfortunately my switch is a (ZigBee) remote with programmable buttons. There´s no physical switch or “light state” I can detect and use. So I´m going to live with my current workaround for a while.

But what about

? There´s a bug in the blueprint, isn´t it?

I don’t have Adaptive Lighting installed. But from the integration’s description, it’s not compatible with this blueprint. This blueprint monitors target entity’s state. So you are right, if other automation is changing the light’s brightness, this blueprint may not work. I will think about a solution if possible.

Regarding the original issue you mentioned, you can create a helper entity to mock the physical switch. Basically you need to create a input_boolean Input Boolean - Home Assistant, then use your zigbee remote to toggle this input_boolean. Then in the blueprint, use this as blocker_entity.

1 Like

Finally I understand what the blocker entities are made for :wink: Same result but automation can stay active. Works! I used

    timeout_blocker_entity: input_boolean.light_manual
    timeout_blocker_entity_state: 'on'

But I still don´t get it: what is the target_entity_state: '' ((Optional) Target Entity Desired State) for? Because it simply is NOT working as described in the blueprint:
grafik
→ That just don´t work. If it would work, I would not need to have the blocking entity. So I still believe something´s not working as intended/described/designed.

That would be awesome! Would reduce the complexity around the blueprint a lot (and I don´t think my usecase is that special, so others will benefit from such a solution too) :slight_smile:

I will think about a solution for this

1 Like

Sorry to bother you once again, but as I´m using this great blueprint more and more for different things in my home, I not only run into limitations or discover bugs but also imagine optimizations/feature enhancements, some by little to no cost. Here´s one:

Could you add the option to support (select/enter/use) multiple illuminance sensors?

I already experimented with a group but illuminance sensors are not supported according to domain list at Group - Home Assistant and therefore group value was “unknown”. And a second automation is neither smart nor trouble-free. So:

I have a valid use case for this and you have already implemented the basic feature for other parts of the blueprint, e. g. (OPTIONAL) Alternate Trigger Timeout. This could look like…
A) …when keeping the current structure:

  • (Optional) Illuminance Sensor: sensor.illuminance1,sensor.illuminance2
  • (Optional) Illuminance Below: value1,value2

B) …after merging (Optional) Illuminance Sensor and (Optional) Illuminance Below to one field (like already done with (OPTIONAL) Alternate Trigger Timeout):

  • sensor.illuminance1,value1;sensor.illuminance2,value2

→ The automation should work, if ANY of the listed illuminance sensors provided is below the corresponding value (sensor.illuminance1 below value1, sensor.illuminance2 below value2 and so on). :white_check_mark: I´d be happy to test that!

You could also make a template sensor to combine your sensors by picking the one with the lowest value.

Nice :+1:t3: But a) every sensor has its own cutoff value so just going for the lower one is not sufficient and b) why not have it in the blueprint so more people can use it (much more handy without templating and stuff) :grinning:

Gotcha, but I didn’t say it shouldn’t be added. I was offering an alternative (albeit a bit different). I understand your main use case and it seems entirely valid. :slight_smile:

You also mentioned groups and to me it seems the only way groups could work is if there is some rule to combine/fuse sensors (min, max, avg) — should the HA team see a need to implement such a feature for groups. I was thinking about this when I made my previous post.

After updating to this version I now have different issue. For some reason the light never turns on (I checked motion sensor is working fine)

    - id: <some identifier>
      alias: <human readable alias>
      description: ''
      use_blueprint:
        path: kevinxw/state_based_entity_control.yaml
        input:
          trigger_entity: binary_sensor.<entity id of my motion sensor>
          target_entity: light.<entity id of my light to turn on/off>
          alt_trigger_timeout: '18:00:00-22:00:00,00:10:00;05:00:00-08:00:00,00:10:00'
          trigger_timeout: '60'
          blocker_entity: switch.control_mode
          blocker_entity_state: 'off'
          timeout_blocker_entity: switch.control_mode
          timeout_blocker_entity_state: 'off'
          sun_elevation_below: 7

Are you using the latest home assistant? If yes, you can go to the corresponding automation and click “show trace”. At the trigger layer click “show changed variables”, from there I can tell what conditions are not met.

When motion detected it triggers twice:
First:

trigger:
  platform: state
  entity_id: binary_sensor.0x00158d000462dce1_occupancy
  from_state:
    entity_id: binary_sensor.0x00158d000462dce1_occupancy
    state: 'off'
    attributes:
      battery: 100
      linkquality: 63
      occupancy: false
      voltage: 3035
      friendly_name: Кухня движение
      device_class: motion
    last_changed: '2021-05-05T12:17:02.154532+00:00'
    last_updated: '2021-05-05T12:17:02.154532+00:00'
    context:
      id: 3e6061e9c4ff1cb4b344b90f2779a001
      parent_id: null
      user_id: null
  to_state:
    entity_id: binary_sensor.0x00158d000462dce1_occupancy
    state: 'off'
    attributes:
      battery: 100
      linkquality: 60
      occupancy: true
      voltage: 3035
      friendly_name: Кухня движение
      device_class: motion
    last_changed: '2021-05-05T12:17:02.154532+00:00'
    last_updated: '2021-05-05T12:17:37.664541+00:00'
    context:
      id: bb10af1eed3e511a0c34cfa20f57b354
      parent_id: null
      user_id: null
  for: null
  attribute: null
  description: state of binary_sensor.0x00158d000462dce1_occupancy
  id: '2'
_target_entity: light.switch_kitchen_0x00158d00054408ee
target_entity: light.switch_kitchen_0x00158d00054408ee
_target_entity_off: null
target_entity_off: light.switch_kitchen_0x00158d00054408ee
_target_entity_state: 'on'
target_entity_state: 'on'
_target_entity_action_on: homeassistant.turn_on
target_entity_action_on: homeassistant.turn_on
_target_entity_action_off: homeassistant.turn_off
target_entity_action_off: homeassistant.turn_off
_trigger_entity: binary_sensor.0x00158d000462dce1_occupancy
trigger_entity: binary_sensor.0x00158d000462dce1_occupancy
_trigger_entity_state: 'on'
trigger_entity_state: 'on'
_trigger_entity_state_off: null
trigger_entity_state_off: ''
_trigger_timeout: '60'
illuminance_sensor: null
illuminance_below: null
blocker_entity: switch.control_mode
_blocker_entity_state: 'off'
blocker_entity_state: 'off'
timeout_blocker_entity: switch.control_mode
_timeout_blocker_entity_state: 'off'
timeout_blocker_entity_state: 'off'
_alt_trigger_timeouts: null
_alt_trigger_timeout: ''
trigger_timeout: 60
_execution_time_ranges: null
execution_time_ranges: ''
execution_time_range_matched: ''
trigger_entities_available: 'binary_sensor.0x00158d000462dce1_occupancy:on;'
trigger_entities_matched: 'binary_sensor.0x00158d000462dce1_occupancy:on;'
trigger_entities_off_matched: ''
target_entities_matched: 'light.switch_kitchen_0x00158d00054408ee:on;'
triggered_entity: binary_sensor.0x00158d000462dce1_occupancy
sun_elevation_below: 7

second:

trigger:
  platform: state
  entity_id: binary_sensor.0x00158d000462dce1_occupancy
  from_state:
    entity_id: binary_sensor.0x00158d000462dce1_occupancy
    state: 'off'
    attributes:
      battery: 100
      linkquality: 60
      occupancy: true
      voltage: 3035
      friendly_name: Кухня движение
      device_class: motion
    last_changed: '2021-05-05T12:17:02.154532+00:00'
    last_updated: '2021-05-05T12:17:37.664541+00:00'
    context:
      id: bb10af1eed3e511a0c34cfa20f57b354
      parent_id: null
      user_id: null
  to_state:
    entity_id: binary_sensor.0x00158d000462dce1_occupancy
    state: 'on'
    attributes:
      battery: 100
      linkquality: 60
      occupancy: true
      voltage: 3035
      friendly_name: Кухня движение
      device_class: motion
    last_changed: '2021-05-05T12:17:37.667543+00:00'
    last_updated: '2021-05-05T12:17:37.667543+00:00'
    context:
      id: 7f61e27a5e04bd9c07de4ad18618a6db
      parent_id: null
      user_id: null
  for: null
  attribute: null
  description: state of binary_sensor.0x00158d000462dce1_occupancy
  id: '2'
_target_entity: light.switch_kitchen_0x00158d00054408ee
target_entity: light.switch_kitchen_0x00158d00054408ee
_target_entity_off: null
target_entity_off: light.switch_kitchen_0x00158d00054408ee
_target_entity_state: 'on'
target_entity_state: 'on'
_target_entity_action_on: homeassistant.turn_on
target_entity_action_on: homeassistant.turn_on
_target_entity_action_off: homeassistant.turn_off
target_entity_action_off: homeassistant.turn_off
_trigger_entity: binary_sensor.0x00158d000462dce1_occupancy
trigger_entity: binary_sensor.0x00158d000462dce1_occupancy
_trigger_entity_state: 'on'
trigger_entity_state: 'on'
_trigger_entity_state_off: null
trigger_entity_state_off: ''
_trigger_timeout: '60'
illuminance_sensor: null
illuminance_below: null
blocker_entity: switch.control_mode
_blocker_entity_state: 'off'
blocker_entity_state: 'off'
timeout_blocker_entity: switch.control_mode
_timeout_blocker_entity_state: 'off'
timeout_blocker_entity_state: 'off'
_alt_trigger_timeouts: null
_alt_trigger_timeout: ''
trigger_timeout: 60
_execution_time_ranges: null
execution_time_ranges: ''
execution_time_range_matched: ''
trigger_entities_available: 'binary_sensor.0x00158d000462dce1_occupancy:on;'
trigger_entities_matched: 'binary_sensor.0x00158d000462dce1_occupancy:on;'
trigger_entities_off_matched: ''
target_entities_matched: 'light.switch_kitchen_0x00158d00054408ee:on;'
triggered_entity: binary_sensor.0x00158d000462dce1_occupancy
sun_elevation_below: 7

The light did not turned on

It’s weird. Could you check the light’s state in Developer Tool in Home Assistant when it happens?
The trace info you posted showed the light.switch_kitchen_0x00158d00054408ee is already on

Thanks. You were right. The problem was not in automation or blueprint, it was in switch hardware. I reset the switch and it started working.

PROBLEM / BUG: Optional condition is not re-evaluated

Situation:
I have a trigger entity (presence sensor) and an illuminance sensor.

Problem:
automation is triggered on every trigger entity state change (good), BUT the illuminance sensor value is not re-evaluated anymore:

In detail:

  • It’s dark. I enter the room, light (target entity) is being turned on. Good.
  • Now after some time while still in the room and constantly triggering the automation (presence sensor/trigger entity) it’s getting bright so we jump over the illuminance sensor threshold.
  • BUT the light is still and stays on!
  • I need to either manually turn it off once or leave the room until the light gets turned off automatically (timeout).
  • After that, on next automation trigger the illuminance sensor value is correctly re-evaluated and light stays off.

So it looks like only the trigger entity is monitored OR the illuminance sensor is only used ONCE (on first automation trigger).

We could have a deeper look at this by diving into the automation trace logs but hopefully you can confirm and fix this without more data.

@kevinxw: Let me know if you need more information, consider this as a bug you can confirm or maybe something with my automation configuration is totally wrong.

This behavior is exactly what I expected. It make no sense to me that if a people enter a room when it’s dark, then the light got turned on so it’s no longer dark enough, and the light got turned off… you will find yourself in a loop of the “light on → light off → light on” situation.

This blueprint is great! Only thing I’d love to add, is being able to send data to the turn_on service. Specifically, I’d love to be able to set the brightness of the lights to a number which is derived from a calculation based off of my light sensor. So that when it’s very dark (middle of the night), it sets brightness to 10%, but when it’s just slightly dark, set it to 30%.

Something like (sensor.light_sensor.state / 10) * 3

OK. When I enter the room and it’s dark, light turns on. But NOW I
a) open the blinds or
b) switch on another light manually or
c) …
and it’s not dark anymore, but light is still on.

It also depends where you locate the illuminance sensor.

While I understand the basic deadlock situation, on the other hand there are use cases where it is annoying. Therefore I propose to add a „take optional brightness sensor into account“ option, turned off by default. If activated, entity is used together with trigger entity to decide if target entity will be changed.

Is it possible to implement this please @kevinxw ?

Better use integrations like „Adaptive Lighting“ for this.

Cool, thanks - I’ll look into it.

This sounds like a great feature as I have dimmable lights. I will add it when I have time.