Entity Controller Mega Thread (Motion Lighting Controller)

Tags: #<Tag:0x00007fc407674a58>

I have an app based on stock motion_light app which I have been testing for last few months. Works for the most part.


What doesn’t work?

The way app works is:
Outer motion detected > door opened > internal motion detected = light on for 10 min
if door closed and another internal motion detected > keep 10 min else timer reset to 60 sec.
There is a bug in the logic somewhere so that the timer is not reset some of the time, I am too lazy to go through the app to debug.

Can you raise an issue for this and include your configuration?

I think we need to have a class to describe the room in a house with properties like doors, lights, fans and occupancy to properly control lights, fans etc. I tried to make one but failed due to my poor programming skills.
Anyway my reasoning for the app goes like this:

If the room has only one door(Toilet does):
    >> If motion detected inside
               >> Room must be occupied( Unless the previous state was unoccupied and the door has not opened recently: false positive)    
                     >> If the room is occupied light must be on(With conditions) until the door opened again(to let the occupant out)

I will raise an issue if you like to further discuss.

I meant raise an issue for the bug you found.

This is completely unrelated functionality…

This would only apply to toilets. Any other room you could have multiple people entering

i think you look at it from the wrong direction. without creating special apps (and quite some programming) your way should be this:

create a timer

and 3 simple automations like

  door is opened 
  lights are off 
  start a timer

  door is opened 
  lights are on 
  turn lights off

  motion detected 
  timer is on and lights are off
  turn lights on
reset timer

now the lights will only go on if the door has been opened and motion is detected within the timer time
and the lights will only go off if the door is opened again


this is GREAT @danny

Maybe I’m misunderstanding something, but when I add the example from the doc in my configuration file, I get this error in my log:

Failed config
  General Errors: 
    - Component not found: lightingsm

is there something I need to do to add this component to Home Assistant? From reading the doc it sounded like the component should be available.

You need to add it as a custom component

unrelated but I’m so happy I’m not the only person in the world with a mudroom. So many people ask me what that is :slight_smile:

Good stuff @danny it’s a very slick idea.

Mudroom is the most used place in the house as almost every entry or exit occurs from it.

It also has special abilities like a black-hole to consume kids homework and sometimes the occasional random winter mitt.

@jwelter you have no idea how vindicated I feel right now :wink:

Awsome component, probobly best I ever used!
Thank you @danny !

1 Like

Hi I do not understand from github how the new installation works. Can anyone please help?

Before I just put lightingsm: in configuration and the file lightingsm.yaml in config folder, and lightingsm.py in custom_component…

and now?

Create a folder “entity_controller” under “custom_components” and copy the file “init.py” from github in this folder.

Or use the custom_updater for installation and updating.

I just saw that the filename was set to bold. The file must have 2 underscores at the beginning and at the end.

1 Like

Thanks for this component. I now use appdaemon for my bathroom motion light. In appdaemon i change light brightness to 50 for 15 seconds before turning it off. If it is in night mode raised it to 50 and if it is day mode lower to 50. Can i somehow mimic that in your component?

You could try custom service call parameters.

Can i run script instead light.turn_off? I want to change brightness for 10 seconds before turning off light. But every time i get error. Scripts work if i run them manually.


    sensor: input_boolean.sensor1                                  
    sensor_type: duration                                                 
    entity: light.bed_light                                                   
    delay: 10                                                                 
      brightness: 250                                              
    entity_off: script.bed_light_off                                                                                               
        brightness: 10                                             
      delay: 10                                                           
      start_time: '22:00:00'                                                  
      end_time: '07:00:00'                                                    
      entity_off: script.bed_light_off_night_mode     


  alias: "Bed light off"                                                        
    - service: light.turn_on                                                    
      entity_id: light.bed_light                                                
        brightness: 50                                                          
    - delay:                                                                    
        seconds: 10                                                             
    - service: light.turn_off                                                   
      entity_id: light.bed_light                                                                                          
  alias: "Bed light off"                                                        
    - service: light.turn_on                                                    
      entity_id: light.bed_light                                                
        brightness: 50                                                          
    - delay:                                                                    
        seconds: 10                                                             
    - service: light.turn_off                                                   
      entity_id: light.bed_light     


2019-03-08 14:40:39 DEBUG (SyncWorker_17) [custom_components.entity_controller.motion_light] Turning on s
2019-03-08 14:40:39 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/tmp/tcloop/python3.6.4/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/tc/.homeassistant/custom_components/entity_controller/__init__.py", line 381, in sensor_state_change
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 383, in trigger
    return self.machine._process(func)
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 1047, in _process
    return trigger()
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 254, in _trigger
    return self._process(event_data)
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 409, in _process
    if trans.execute(event_data):
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 210, in execute
    return _super(NestedTransition, self).execute(event_data)
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 263, in execute
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 218, in _change_state
    lvl = source_state.exit_nested(event_data, dest_state)
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 153, in exit_nested
    return self.parent.exit_nested(event_data, target_state)
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 165, in exit_nested
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 127, in exit
    event_data.machine.callback(handle, event_data)
  File "/home/tc/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 1005, in callback
    func(*event_data.args, **event_data.kwargs)
  File "/home/tc/.homeassistant/custom_components/entity_controller/__init__.py", line 563, in on_exit_active
  File "/home/tc/.homeassistant/custom_components/entity_controller/__init__.py", line 869, in turn_off_control_entities
    self.call_service(e, 'turn_on')
  File "/home/tc/.homeassistant/custom_components/entity_controller/__init__.py", line 1105, in call_service
    domain, e = entity.split('.')
ValueError: not enough values to unpack (expected 2, got 1)