Entity Controller Mega Thread (Motion Lighting Controller)

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

Prefect!!:smiley:

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

trigger:
  door is opened 
condition:
  lights are off 
action:
  start a timer

trigger:
  door is opened 
condition:
  lights are on 
action:
  turn lights off

trigger:
  motion detected 
conditions:
  timer is on and lights are off
actions:
  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

4 Likes

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.

1 Like

@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.

Edit:
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.
SOLVED.
https://github.com/danobot/entity-controller/issues/42

Configuration:

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

Scripts:

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

Error:

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
    self.sensor_off_duration()
  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
    self._change_state(event_data)
  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
    tmp_self.exit(event_data)
  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
    self.turn_off_control_entities()
  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)