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)

Right, this blueprint is not the perfect solution for my simple scenario, a usual automation does the trick.

FYI: I tried to set the timeout to 24:00:00 but the light was turned off anyway. And very strange: every time I tried to turn it on, it was immediately turned off again. So I think the automation will stay active until the timeout is reached (or HA has been restarted meanwhile I guess) so that´s just a mess.

Again, a simple automation is fine for my scenario. But there´ll be other scenarios where this blueprint will be just perfect, I´ll keep it :slight_smile:

That could be a bug. It shouldn’t turn off immediately.

Try this one:

alias: Light on dusk to dawn
description: ''
use_blueprint:
  path: kevinxw/state_based_entity_control.yaml
  input:
    trigger_entity: sun.sun
    trigger_entity_state: below_horizon
    target_entity: light.your_light_id
    trigger_timeout: '0'
    sun_elevation_below: '0'
    timeout_blocker_entity: sun.sun
    timeout_blocker_entity_state: above_horizon

Great blueprint. Thanks! It would also be very handy to be able to define more than one target entity.

Multiple target entity is not directly supported due to limitation of blueprint (I cannot add input fields dynamically).
But assuming your target entities share the same states, you can group them and use the group as target.
In my case, I have multiple light in my living room, so I just group them then let the automation turn on group.living_room_lights instead.

1 Like

I updated the blueprint and now it supports multiple states. You can import the new blueprint using this address https://github.com/kevinxw/homeassistant/blob/0c97e36c35838a3d7eaadda527b7a3ca04197420/blueprints/state_based_entity_control.yaml
Tell me how it works for you.

Edit: Please use the blueprint URL in the top post. This function has been merged there.

OK, here´s what I´d like to do (and this blueprint seems to be just perfect for it - it just doesn´t work):

1st) I want to use two to three of this blueprint automations to set a “room presence entity” to ON:

  • automation 1: motion triggered
  • automation 2: vibration triggered

Every automation shall set a input_boolean.room_presence to ON when being triggered and turn it OFF after a certain timeout.

2nd) I want to use the input_boolean.room_presence as trigger for turning things like lights etc. on afterwards.

That´s the plan. Here´s reality:

1) Feature request: It seems like trigger_timeout only accepts hard coded values (seconds). Is it possible to also accept entities? I´d like to use a helper entity “input_number.timeout”.

2) Bug report: I discovered a bug. Not sure where exactly, but: with your never blueprint version (after February 2nd) my automation only turns the target entity ON, but never OFF.
This is the log book of the target entity:
grafik
This is the automation:

alias: Presence_Room 1_Trigger Motion
description: Trigger Motion as Input for Presence Status
use_blueprint:
  path: kevinxw/state_based_entity_control.yaml
  input:
    trigger_entity: binary_sensor.motion1
    target_entity: input_boolean.presence_room1
    trigger_timeout: '10'
    target_entity_state: 'on'

When I used your version prior the update from February 2nd the target entity has been turned on and off with respecting a hard coded timeout.

I then saw your update and updated the blueprint. Since then the target entity never gets turned on. I think you might have introduced a bug with your release :frowning:

3) Feature request: Having the option to select multiple trigger entities (one motion, one vibration, maybe one door contact etc.) would greatly enhance the options. In my case it would reduce the amount of same automations to just one.

As I can continue using the old blueprint version, 2) is not a big issue for me.
Can you give an estimation if and when you are gonna implement feature requests (no. 1 and no. 3)?

that would be really great to see! :slight_smile:

Hey, I updated the blueprint several times after Feb 2nd, the latest version is at Feb 26. Sorry I didn’t post update on the forum since there was few replies. Try the latest one using the URL from main post, ideally there should be no problem.

trigger_timeout supports seconds and the official time format “HH:MM:SS”, thus it’s a “input_text”. If you adjust the domain it should work.

For multiple trigger entities, this blueprint supports it. I do not have vibration sensor, but I do have door contact sensors and motion sensors, and I do have an automation combining contact sensors and motion sensors. The trick is to create a group with these sensors. I am not very clear what the group’s status will be if you put a vibration sensor there, you can test it by checking the group’s state in developer tool. For group containing only contact sensors and motion sensors, the group’s status will be just on/off.

I have the following group in groups.yaml

garage_motion_door_sensors:
  name: Garage Sensors
  entities:
    - binary_sensor.motion_sensor_158d00020b8046
    - binary_sensor.motion_sensor_158d000116ca1c
    - binary_sensor.door_window_sensor_158d0001a2289f

And an automation like this:

alias: Garage Light
use_blueprint:
  path: kevinxw/state_based_entity_control.yaml
  input:
    trigger_entity: group.garage_motion_door_sensors
    target_entity: switch.garage_light
    illuminance_sensor: sensor.illumination_7811dcdc2cde
    illuminance_below: '450'
    trigger_timeout: '90'

It turns on light when any of these motion sensors detected something or the door is open, and turns off light when everything goes quiet.

1 Like

Hi Kevin

This is really cool and super-helpful!! I am trying to setup a variation - to make a decison on the sum of 3 values subtracted from another. I have tried to use a Helper but figured your blue print could be the solution.

I am on a remote island in the Bahamas and I have a solar array that have intergated as
sensor.power_solar_production_1_1min

And depending on how much power my kitchen and boats are using, I want to control how much power I send to my chargers. I have 1.8kW, 3.3kW and 6.kW that charge my 15kWh, 30kWh and 75kWh battery packs (all ex-Tesla Model S and 3 from crashes)
My chargers are all controlled through Shelly1 relays.

So I need to calculate

   sensor.power_solar_production_1_1min - sensor.power_kitchen_panel_consumption_6_1min - sensor.power_shore_power_1_7_1min - sensor.power_shore_power_2_8_1min

And then trigger the different charge relays

  switch.18kw_charger_relay
  switch.33kw_charger_relay
  switch.66kw_charger_relay

I realize this is a little nuts and unique - and to top it off I only started using HA three weeks ago so I am stumbling around like a drunken sailor. I don’t want to step on anyone’s toes with stupid questions (I likely have), so please forgive me if this is the completely wrong place to post this question!

Thanks
Wayne

Hey Wayne,
That sounds like an interesting project. However, it’s not a fit for this blueprint. This blueprint is only suitable for binary switches (on <-> off etc.). But I have another blueprint may be helpful to you. I use this blueprint to convert my 30 bucks heater to an air conditioner.

The blueprint is at: https://github.com/kevinxw/homeassistant/blob/61b5859dc866edd43da8f5e7cac244e9fbda00b0/blueprints/control_entity_using_sensor_with_numeric_states.yaml
Its concept is simple, when the temperature returned by a climate sensor is above certain value, it turns off the heater; when the temperature is below certain value, it turns on the heater. But the blueprint does not limit itself to heater. You can use it for any sensor that returns a numeric state. I also use it for adjust my humidifier.

From what I understand, you need to create a custom solar power sensor using template. You can find examples here: https://www.home-assistant.io/integrations/template/, you should put the equation you created above into its value_template, so you can rely on that sensor to output a number.

Then, use the blueprint I mentioned above to create 3 automations, which turns on/off your chargers based on the value returned by the sensor you defined above. e.g., when solar power sensor returns a value below 1800 (I suppose the sensor you created will return watt number), turns on switch.18kw_charger_relay, when it’s above 1805 (give some buffer, otherwise the switch may be flapping), turns off switch.18kw_charger_relay, then in the second automation, do the similar but with 3300 as threshold. Then in the third automation, use 6600 as threshold.

I will be interested to see it working.

Awesome - thanks Kevin. Will give it a shot. Hey, if you are ever around the Abaco’s, you are welcome to stop by - it is really beautiful and also a tech paradise. I have built everything myself - I believe I was the first person in the US to take an entire 75kWh Model 3 battery pack and turn it into solar storage. I “fooled” two Danfoss DLX inverters (4.4kW each) into seeing it as a 400V solar field :smile:

I am still very weak at HAss, but trying to get up to speed quickly.

1 Like

Bug in newer versions:
Nope, does not work with latest version. Needed do go back to the old one. Seems like there´s a bug introduced in any newer version. I don´t care a lot currently, still working on tuning the old one to fulfill all requirements.

Multiple trigger entities:
That´s a workaround you use. Can you update the blueprint to simply allow multiple trigger entities? I know how to basically do this in an automation, but no idea how to adjust your blueprint… :frowning:

Your workaround using group entity has a big downside: what if you want to control more than “just” your garage light? Adding another group entity combining all target entities? Setting up a scene? That´s just too much group entity creation considered that an automation is capable of handling the same. Would really love to see this in your blueprint! :slight_smile:

So the main difference is:

  • you use this blueprint for ACTION - to do something based on presence (indicated by a presence group)
  • i use this blueprint for DETECTION - (one to get information from motion sensor, one from vibration sensor - makes 2 automations) to set a presence helper entity, which triggers a separate manual automation doing different things (more than only switching light on)

By being able to select multiple trigger entities this blueprint would not only fit my purpose, it would also allow a much broader usage of it. Ultimate solution would be to being able to set multiple trigger as well as multiple target entities.

What do you think?

OK forget about it, I changed my whole logic and I´m using a group of trigger entities too now.

What I really miss now to replace all my automations based on freakshock88´s blueprint is something he seems to have added after you forked it: a time range condition:

grafik

That´s really the only thing I miss. Can you add this to your blueprint? I really like the broader approach. Time range condition really is the only thing left compared to the original :slight_smile:

Regarding the bug, what exactly is not working?

Multiple trigger entities will not be supported due to the limitation of a blueprint. It only support fixed number of trigger entities. Group is the way to go. If you want to turn on/off multiple entities, create a group for that as well. Everything in that group will be turned on/off.

Yeah as mentioned I got that and changed my whole setup alreay :slight_smile: Last two cents:

  1. I´ve seen another blueprint where using several entities with as special syntax (don´t remember, either “entity1,entity2” or “entity1|entity2” was used, so it is possible.
  2. If one of that actions to be applied to a group of target entities is not just on/off but e. g. “set temperature to XX °” the group entity thing comes to an end quite quickly. BUT as this blueprint is quite general, one could use a script instead which takes care of such extra tasks.

See 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) - #16 by e-raser that´s what I experienced, but I´ll update and test again. As it seems to work for other users, it might be a me specific issue.

@kevinxw: What about 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) - #22 by e-raser ?

I have pushed an update to my blueprint. You can reimport it now. It adds a field letting you specify Execution Time Ranges

If you can show me the link of the blueprint that supports multiple trigger entity, I can probably support that as well.

My automations are running fine with the latest version for 1+ months now. I will be happy to debug if you can provide more details (logs and automation yaml etc.)

Finally I could update to the latest blueprint version and test it. Summary:

  • runs fine without any issues so far
  • could not test the Execution Time Ranges yet (as I added illuminance sensors meanwhile I tend to not use them for now, but there will be situations I´ll have to rely on time instead of illuminance so it´s great to have this option!)
  • really love the updated Alternate Trigger Timeout syntax, very powerful and easy to use

So far: really love that blueprint. Outperforms all similar I´ve seen here and tested (some for weeks) because I like having all configuration in the automation. Other blueprint authors tend to select entities which bloats the user interface or at least you need to create many helper entities.

Regarding

I can say it wasn´t a blueprint I´ve seen, instead it was a regular syntax in a normal automation (trigger section):
grafik

I´m happy so far and will test the updated blueprint for some while. Thank you so much!

I didn’t know home assistant accept this format. It seems very straightforward. I will support multi-entity trigger later.

It looks like the automation does not work without any conditions.
For one instance of blueprint I need just a simple motion sensor trigger → light on.
If I add sun elevation parameter the light starts triggering, but without any additional parameters it does nothing

I have fixed the logic.
If you update the blueprint to the latest version, you can leave both luminance sensor and sun elevation blank.