How to deal with motion lighting and custom lighting scenes/automations

Hi

I’m looking for any advice or examples of how best to deal with motion lighting and custom lighting scenes or automations.

I’ve used home assistant for a few years and as you can imagine I’ve tried multiple incantations of combining custom scenes and automations to deal with transitions between things like:

  • Time of day (block motion when in bed, turn motion on after sunset and before sunrise)
  • Scenes (both in the form of scenes and automations) e.g. watch TV
  • Events doorbell rings turn on porch and hallway light, return to previous state when door shuts/after 5 minutes

I first started my journey with simple automations using home assistant automations. I then added things like input selects for ambiance (night/day/evening/etc). I then used more complex generic automations temaplates that looked at various states to control which lights to turn on when. And then separate automations and scenes to control things like “Watch TV” etc.

I found the number of timers and override input_booleans were getting a bit overwhelming, so moved to entity controller, this simplified things like creating timers for everything and managed states a bit more intelligently. I was able to plug in overrides to control the constraints using automation templates as before to switch an input_boolean to constrain each entity controller.

However I found transitioning between states i.e. constraining an entity was problematic, especially during a transition if a entity controller was already in active_timer or for example the contraint changed or time constraints changed for entity or HA was restarted.

I then started looking at node-red but I found it soon felt over complicated dealing with all the various other states that needed to be considered for each room/light and how the interplay between standard motion lighting, blocking (night time), sun transitions and custom scenes/automations affected things.

I’m a dotnet developer by day so most recently I’ve stumbled across the netdaemon and hhnl.HomeAssistantNet which look quite interesting. I’ve not got in to too much depth with either of these, but with Netdaemon I only seen very basic lighting examples in the attached example repos and again nothing that really deals with that interplay between time of day, motion lighting and custom scenes.

What I’ve started to realise is that regardless of the technology I choose, I am still failing to find an approach where I can consider these different use scenarios and consistently manage the tranistion between things. For example motion lighting in the evening using lights not lamps, but then someone rings the doorbell, so turn the main light on, but then after the door has opened and closed, return back to the motion lighting. (I know that is quite a specific example but what I mean is how to manage transitions between lighting modes and return to previous states).

Currently most of my lighting is working with the entity controllers I described above, but I’ve taken a few rooms out of this like the lounge so I can play with things like use the main light or lamps based on different scenarios. Use the motion sensor for control of the lights and have custom automations/scenes for things like Reading or Watching TV. And also deal with things like don’t turn the lights on during the day or when in bed or manually override the lights without motion control kicking in.

Some features I’ve quite liked with entity controllers are the backoff control and removal of timers for each light. But the transitions as I’ve mentioned have been problematic, often resulting in lights returning to idle state as they’ve been in active timer when a transition has occurred which should have resulted in the state going to overriden or constrained.

I like the code approach of netdaemon or hhnl.HomeAssistantNet, the latter seems most up my street in terms of composition allowing for DI and I’m very comfortable writing C#.

I’ve also started thinking about trying to go down the python route in the form of custom components, this removes some of the additional overhead of the C# addons and I have been meaning to learn python in a bit more detail. Any way as I say the technology isn’t really this issue, other than from a reuse and minimal boiler plate bloat perspective which I would like to keep to a minimum, but clearly I need some advice with an approach on how to deal with these transitions between motion lighting, and other usage scenarios.

Thanks in advance for any direction or examples you can give, again technology is not a concern, I can learn, but the approach is very much my sticking point.

Andy