Code Monkey home page Code Monkey logo

danobot / entity-controller Goto Github PK

View Code? Open in Web Editor NEW
277.0 9.0 41.0 5.47 MB

Home Assistant Entity and lighting controller for managing devices with timers, scripts, and sun-based time restrictions.

Home Page: https://danobot.github.io/ec-docs/

License: GNU General Public License v3.0

Python 98.49% Dockerfile 0.11% JavaScript 0.37% PowerShell 0.52% Shell 0.50%
hass python home-assistant home-automation smart-home finite-state-machine motion-light motion-sensor iot internet-of-things

entity-controller's People

Contributors

actions-user avatar basnijholt avatar brahmafear avatar chishm avatar danielbrunt57 avatar danobot avatar dependabot[bot] avatar dermotduffy avatar dtterastar avatar ecsfang avatar elupus avatar floris-b avatar github-actions[bot] avatar kylerw avatar ludeeus avatar markharleman avatar maxlyth avatar mikeage avatar ndbroadbent avatar piotrmachowski avatar pippyn avatar robchandhok avatar rslota avatar shbatm avatar tabisch avatar wklink avatar xannor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

entity-controller's Issues

2.3.0 - if started inside constrain period it doesn’t exit constrained at correct time

Using 2.3.0 if you restart HA while in the constrained period it stays in constrained mode once the exit time is reached.

For example I have many lights set to start_tiime 06:30:00 and end_time 21:30:00. I restarted at 04:30:00 and they went into constrained mode as expected. When 06:30:00 was reached it remained in constrained mode.

Restarteing after 06:30:00 they went to idle as expected.

Could some logic be reversed if starting while in constrained time? Looking at the logs it appears to me the callback might be set for the enter time versus exit time.

But I’m looking at this on a iPhone while in the air from Copenhagen to Washington DC on very laggy WiFi and I maybe missing something.

Log started when inside allowed time.

019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Entity name: motion_kitchen
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Control Entities: ['light.kitchen_island_pendants']
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Added Control Entities as state entities: ['light.kitchen_island_pendants']
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Sensor Entities: ['binary_sensor.kitchen_pir_sensor']
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Override Entities: ['binary_sensor.auto_lights_override']
2019-01-12 07:54:10 INFO (MainThread) [custom_components.lightingsm.motion_kitchen] serivce data set up: OrderedDict([('sensors', ['binary_sensor.kitchen_pir_sensor']), ('entities', ['light.kitchen_island_pendants']), ('delay', 1800), ('sensor_type_duration', True), ('start_time', '06:30:00'), ('end_time', '20:00:00'), ('overrides', ['binary_sensor.auto_lights_override']), ('name', 'motion_kitchen')])
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Next sunrise: 2019-01-12 07:24:22-05:00
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Next sunset: 2019-01-12 17:03:57-05:00
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Constrain callback for : 2019-01-13 06:30:00
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Next sunrise: 2019-01-12 07:24:22-05:00
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Next sunset: 2019-01-12 17:03:57-05:00
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Constrain callback for : 2019-01-12 20:00:00
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Constrains - Entity active from: 2019-01-13 06:30:00
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Constrains - Entity active until: 2019-01-12 20:00:00
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Config other
2019-01-12 07:54:10 DEBUG (MainThread) [custom_components.lightingsm.motion_kitchen] Using DAY MODE parameters: {'delay': 1800, 'service_data': None}
2019-01-12 

Time constraints getting lost on 2.2.10

2.2.10 had been working well for several days now, but interestingly after a few days the time time constraints are no longer respected. The motion config shows ‘idle’ for status versus ‘constrained’ and is active. But other motion condors with the same constraints seem to be ok so it’s not all being lost. A restart fixes it and immediate shows the constrained status

Did anything change recently: lights go from off to on, outside trigger period

Now its 08:00 (outside the time of the configuration) and with motion the lights go from off to on (in plain day)

Until yesterday this was not happening


  dining_room_evening: 
    sensors: 
          - binary_sensor.pir_living_two
          - binary_sensor.pir_living_four
          - binary_sensor.pir_stairs_up
          - binary_sensor.pir_stairs_down
    entities: 
          - light.chandelier_one
          - light.chandelier_two
          - light.chandelier_three
    start_time: sunset    
    end_time: '23:59:59'
    delay: 360
    sensor_type_duration: True
    overrides:
          - input_boolean.motion_dining_evening
          - input_boolean.dining_stop_off

  dining_room_night: 
    sensors: 
          - binary_sensor.pir_living_two
          - binary_sensor.pir_living_four
          - binary_sensor.pir_stairs_up
          - binary_sensor.pir_stairs_down
    entity: light.chandelier_one
    service_data:
            brightness: 80
    start_time: '00:00:01'
    end_time: '07:00:00'
    delay: 65
    sensor_type_duration: True
    overrides:
          - input_boolean.motion_dining_night

receive this error, do not understand the error in config

2019-01-12 20:35:32 ERROR (MainThread) [homeassistant.setup] Error during setup of component lightingsm
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/setup.py", line 145, in _async_setup_component
hass, processed_config)
File "/config/custom_components/lightingsm.py", line 118, in async_setup
m = LightingSM(hass, config, machine)
File "/config/custom_components/lightingsm.py", line 141, in init
self.model = Model(hass, config, machine, self)
File "/config/custom_components/lightingsm.py", line 251, in init
self.config_sensor_entities(config)
File "/config/custom_components/lightingsm.py", line 586, in config_sensor_entities
event.async_track_state_change(self.hass, self.sensorEntities, self.sensor_state_change)
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/event.py", line 62, in async_track_state_change
entity_ids = tuple(entity_id.lower() for entity_id in entity_ids)
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/event.py", line 62, in
entity_ids = tuple(entity_id.lower() for entity_id in entity_ids)
AttributeError: 'NodeListClass' object has no attribute 'lower'

override entities on restart

On a restart, the override entities are not respected.

This behaviour makes sense to me, since the override mode kicks into action upon a state change of any of the override entities defined,

This however becomes a problem when I rely on the override entity to control (disable) auto lights based on external rules. When HA is restarted (for whatever reason) the entity controller will go back into 'idle' state, as it does not read the state of the override entities upon startup.

This is technically not a bug, but rather a request for behaviour.

I can set up a workaround to re-trigger the single override entity after a restart.

Turns off light while motion is active

I use xiaomi motion sensors.
And they trigger motion only once, until there is no motion for ~30 seconds.

The issue is that this app turns off light while motion binary sensor is still active.

AttributeError in logs

I'm using version 3.1.1 on homeassistant version 0.87.1. After upgrading to 3.1.1 with the new name and directory structure I am seeing this error peppered occasionally throughout the log file:

Error doing job: Future exception was never retrieved

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/entity_controller/__init__.py", line 317, in sensor_state_change
    self.sensor_on()
  File "/usr/local/lib/python3.6/site-packages/transitions/core.py", line 383, in trigger
    return self.machine._process(func)
  File "/usr/local/lib/python3.6/site-packages/transitions/core.py", line 1047, in _process
    return trigger()
  File "/usr/local/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 254, in _trigger
    return self._process(event_data)
  File "/usr/local/lib/python3.6/site-packages/transitions/core.py", line 409, in _process
    if trans.execute(event_data):
  File "/usr/local/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 210, in execute
    return _super(NestedTransition, self).execute(event_data)
  File "/usr/local/lib/python3.6/site-packages/transitions/core.py", line 263, in execute
    self._change_state(event_data)
  File "/usr/local/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 218, in _change_state
    lvl = source_state.exit_nested(event_data, dest_state)
  File "/usr/local/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 149, in exit_nested
    self.exit(event_data)
  File "/usr/local/lib/python3.6/site-packages/transitions/core.py", line 127, in exit
    event_data.machine.callback(handle, event_data)
  File "/usr/local/lib/python3.6/site-packages/transitions/core.py", line 1005, in callback
    func(*event_data.args, **event_data.kwargs)
  File "/config/custom_components/entity_controller/__init__.py", line 529, in on_exit_blocked
    if self.block_timer_handle.is_alive():
AttributeError: 'NoneType' object has no attribute 'is_alive'

Looks like it may just need an extra check to ensure self.block_timer_handle is set before attempting to access the attribute. I haven't looked closely at the code to determine why it isn't set in this particular case.

My configuration if it's useful:

entity_controller:
  mtn_back_door:
    sensor: binary_sensor.xioami_motion_sensor_2
    sensor_type_duration: true
    entities: 
      - light.kitchen
      - switch.kitchen_ikea_tradfri_outlet
    delay: 200

Readme file is talking about old version

I am not so familiar with github, so i hope this feedback is the right place:

Under basic configuration in the readme, it says:
"Note: The top-level domain key lightingsm will be omitted in the following examples."

I think it is supposed to say "entity_controller" instead of "lightingsm"?

If in constrained period and override is set it’s ignored when constraint ends

I have kids rooms set with a motion constraint to allow operating from 8am to 8pm.

I also have a override that comes on if bright enough we don’t need lights.

That override was tripped at 7:58am but when constraint ended at 8am it was ignored

I think we need to check override sensor state when entering and exiting constrained period?

Exception error "can't trigger event sensor_on from state blocked!" on v2.2.8

2019-01-01 16:25:55 DEBUG (SyncWorker_15) [custom_components.lightingsm.motion_office] Sensor state change: on
2019-01-01 16:25:55 DEBUG (SyncWorker_15) [custom_components.lightingsm.motion_office] state: blocked
2019-01-01 16:25:55 DEBUG (SyncWorker_15) [custom_components.lightingsm.motion_office] matches on
2019-01-01 16:25:55 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/lightingsm.py", line 291, in sensor_state_change
    self.sensor_on()
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 383, in trigger
    return self.machine._process(func)
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 1047, in _process
    return trigger()
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 251, in _trigger
    raise MachineError(msg)
transitions.core.MachineError: "Can't trigger event sensor_on from state blocked!"

Dates are wrong

Today is first February at 8.30 lights do not go from off to on (note that start time date is second of February, tomorrow

master_bedroom_morning:
sensor: binary_sensor.pir_under_master_bedroom
entity: switch.light_bedroom_wall
start_time: '08:00:00'
end_time: '08:59:59'
delay: 120
sensor_type_duration: True
overrides:
- binary_sensor.holiday_lights_override

2.3.2: On starting several "AttributeError: 'NoneType' object has no attribute 'state'" errors are thrown

2019-01-13 09:06:46 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/lightingsm.py", line 291, in sensor_state_change
    self.sensor_on()
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 383, in trigger
    return self.machine._process(func)
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 1047, in _process
    return trigger()
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 254, in _trigger
    return self._process(event_data)
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 409, in _process
    if trans.execute(event_data):
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 210, in execute
    return _super(NestedTransition, self).execute(event_data)
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 254, in execute
    if not cond.check(event_data):
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 182, in check
    return predicate(*event_data.args, **event_data.kwargs) == self.target
  File "/home/homeassistant/.homeassistant/custom_components/lightingsm.py", line 427, in is_state_entities_off
    return self._state_entity_state() is None
  File "/home/homeassistant/.homeassistant/custom_components/lightingsm.py", line 420, in _state_entity_state
    if self.matches(s.state, self.STATE_ON_STATE):
AttributeError: 'NoneType' object has no attribute 'state'

Feature request: morning and evening mode

From my user case I see a pattern of usage which is distinct from day and night mode. Specifically I have different needs in 4 phases : morning, day, evening, night.

Maybe is possible to add to the component 2 additional phases to have 4 in total?
(morning, evening to be added to day (standard) and night mode?

Component entity_controller does not exist

Hi,

Following the instructions, I cloned the repo (v.3.3.3) and then moved the entity_controller folder to my custom_components folder. Now it looks like this:

usuario@ha:~/.homeassistant/custom_components/entity_controller$ ls
 __init__.py  __pycache__

I did a minimal configuration and put it on a package which looks like this:

$ cat packages.d/quartinho.yaml
entity_controller:
  quartinho_motionlight:
      sensor: binary_sensor.quartinho_rf
      entity: light.quartinho
      delay: 60

But when I try to check the new configuration with hass --script check_config, I got this:

Failed config homeassistant.packages.quartinho.entity_controller:
    - Package quartinho setup failed. Component entity_controller does not exist
    - entity_controller: [source /home/usuario/.homeassistant/packages.d/quartinho.yaml:1]
    quartinho_motionlight: [source /home/usuario/.homeassistant/packages.d/quartinho.yaml:2]
          delay: 60
          entity: light.quartinho
          sensor: binary_sensor.quartinho_rf
Successful config (partial)
  homeassistant.packages.quartinho.entity_controller:

I'm on the last HA version (0.91.1) but got the same issue with 0.90. What I'm doing wrong? Or is this a bug?

Exception errors during sensor_type_duration: True

Seems if this config option is set it requires some other state machine entries which are not present; so it throws an error.

I didn't manage to catch the logs but can re-test and grab them if needed.

Note: I set this as I am trying to use some door open/close sensors as triggers and they behave in the way this configuration option defines.

using a scene for entity_on does not work

If you specify a scene for entity_on, the state is always "scening" which results in:

... INFO xxx Motion Lights: Motion Sensor binary_sensor.xxx_motion triggered
... INFO xxx Motion Lights: Current state of scene.xxx_on_dim is scening
... INFO xxx Motion Lights: Entity is already switched on. Motion trigger ignored.

because if entityState == "off": will never be true for a scene.

Perhaps:

if entityState != "on", although I don't know what other affects that may have.

Overrides not working (probably because sensor was idel/active?)

Now its 23:00:00, the input_boolean is on (I checked), but the component is idle, and with a movement all the lights go ON.

My goal is: I am sitting in my living room with lights ON, I want to turn ON my projector, and turn OFF the lights, since I have the lightingsm component for triggering the lights with motion, I need to turn this feature OFF (put manually in front-end an input_boolean to ON, and this input_boolean is in ovveride section) also WHILE sitting in the living room.

Maybe lightingsm did not work because when I turned ON the input_boolean (the override) the component was active (idle or active_timer)?


  dining_room_evening: 
    sensors: 
          - binary_sensor.pir_living_two
          - binary_sensor.pir_living_four
          - binary_sensor.pir_stairs_up
          - binary_sensor.pir_stairs_down
    entities: 
          - light.chandelier_one_2
          - light.chandelier_two_2
          - light.chandelier_three_2
    start_time: '17:00:00'   # change when sunset will work
    end_time: '23:59:59'
    delay: 360
    sensor_type_duration: True
    overrides:
          - input_boolean.motion_dinimg_evening

Name change discussion

This component has become more than a simple motion lighting controller. Initially I wanted to call it LightingSM (Lighting State Machine), but I feel it requires a more generic name. This issue is to discuss possible alternatives.
The repository will have to be renamed too because it may mislead people thinking they need appdaemon.
The domain will be renamed to match as well. (Breaking change for a future v3)

One name I thought of was

  • entity_timer

@jwelter1971

Never returns to idle from blocked

All entities have gone back to off, but the entity_controller is still blocked.

image
image

config:

  sensors:
    - binary_sensor.motion_playroom
    - binary_sensor.motion_oliwers_room
    - binary_sensor.motion_eliaz_room
    - binary_sensor.motion_lowas_room
    - binary_sensor.motion_bathroom
  entities:
    - switch.fibaro_system_fgs221_double_relay_switch_2x15kw_switch
    - light.playroom_lamp
  start_time: '20:00:00'
  end_time: '06:00:00'
  delay: 60
  overrides:
    - input_boolean.kids_nightlights_off

Problem with calling custom scripts

I want to change brightness for 10 seconds before turning off light. But every time i get error Error doing job: Future exception was never retrieved. And entity controller get stuck with active_timer. Scripts work if i run them manually.

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: 25                                                          
    - delay:                                                                    
        seconds: 10                                                             
    - service: light.turn_off                                                   
      entity_id: light.bed_light                                                
                                                                                
bed_light_off_night_mode:                                                       
  alias: "Bed light off night mode"                                             
  sequence:                                                                     
    - service: light.turn_on                                                    
      entity_id: light.bed_light                                                
      data:                                                                     
        brightness: 25                                                          
    - delay:                                                                    
        seconds: 10                                                             
    - service: light.turn_off                                                   
      entity_id: light.bed_light    

ERROR:

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)

Feature request: More flexible override entities

It would be nice if the override entities could be set per sensor, for instance if you want it to trigger on motion A, or (motion B if state C) (but A should be triggered no matter the state. You can make two motion lights that both have the same control entity. This however means that it can turn off to early if you have more than 1 sensor, because it will turn off when the first sensor has been off for 180 seconds, even if the second has been activated later.

It would also be nice if there was an "override on off", option in addition to the default "override on on", you can solve it with a input_boolean or something, but it would be easier and more elegant to be able to set it directly as a parameter.

REQUEST: timer_sensors

I'd like to be able to start the timer/delay when a sensor triggers (my use case is when the light switches on) and at the end of the timer/delay turn it off unless the sensors (motion sensor) is triggered during the time/delay which would reset it.

Basically I'm looking for a way to turn off lights that were turned on manually unless motion is detected (or similar).

Strange error during component initialization

Hi I get the following error in the logs during startup.

ERROR (MainThread) [homeassistant.loader] Error loading custom_components.entity_controller. Make sure all dependencies are installed
Mar 18 19:37:15 hassbian hass[2210]: Traceback (most recent call last):
Mar 18 19:37:15 hassbian hass[2210]: File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 92, in get_component
Mar 18 19:37:15 hassbian hass[2210]: module = importlib.import_module(path)
Mar 18 19:37:15 hassbian hass[2210]: File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module
Mar 18 19:37:15 hassbian hass[2210]: return _bootstrap._gcd_import(name[level:], package, level)
Mar 18 19:37:15 hassbian hass[2210]: File "", line 986, in _gcd_import
Mar 18 19:37:15 hassbian hass[2210]: File "", line 969, in _find_and_load
Mar 18 19:37:15 hassbian hass[2210]: File "", line 958, in _find_and_load_unlocked
Mar 18 19:37:15 hassbian hass[2210]: File "", line 673, in _load_unlocked
Mar 18 19:37:15 hassbian hass[2210]: File "", line 673, in exec_module
Mar 18 19:37:15 hassbian hass[2210]: File "", line 222, in _call_with_frames_removed
Mar 18 19:37:15 hassbian hass[2210]: File "/home/homeassistant/.homeassistant/custom_components/entity_controller/init.py", line 19, in
Mar 18 19:37:15 hassbian hass[2210]: from transitions import Machine
Mar 18 19:37:15 hassbian hass[2210]: ImportError: No module named 'transitions'

However 'transitions' is installed; however the component is unable to load the same.

This is on a fresh install of hassbian. Thoughts ?

Any help is appreciated.

Ability to use another entity state as input

Use case is to have a slider in the UI to determine the delay or block_timeout.

something like:

    office_lights:
      sensors: 
        - binary_sensor.basement_multisensor_motion
        - light.office_light_level
        - light.office_lamp_level
      entities: 
        - light.office_light_level
        - light.office_lamp_level
      block_timeout: input_number.office_timout

Add transition time to service_data

Is it possible to add a transition time to service_data? I tried it with this config but it didn't work;

  room:
    sensor: 
      - binary_sensor.motion_sensor
    entity_on: light.light1
    service_data:
      brightness: 255
      transition: 3

No errors in the log, it just ignores the transition.
Expected behaviour should be that the light turns from off to full brightness in 3 seconds.

Enhance documentation for Exponential backoff

Can you please provide an example for appropriate config and use case for exponential backoff.
Want to try it on one or two lights to see how it works in practice. Cant quite figure out from the documentation what the config options should be. Do I still config a delay.... do I have separate expo for night mode?

Still error with start stop time

2019-01-13 10:22:15 DEBUG (MainThread) [custom_components.lightingsm.dining_room] Initialising LightingSM entity with this configuration: OrderedDict([('sensor', ['binary_sensor.pir_living_two', 'binary_sensor.pir_living_three', 'binary_sensor.pir_stairs_up', 'binary_sensor.pir_stairs_down']), ('entity', 'light.chandelier_one'), ('service_data', OrderedDict([('brightness', 80)])), ('start_time', '00:00:00'), ('end_time', 'sunrise'), ('delay', 65), ('sensor_type_duration', True), ('name', 'dining_room')])
2019-01-13 10:22:15 DEBUG (MainThread) [custom_components.lightingsm.dining_room] Entity name: dining_room
2019-01-13 10:22:15 DEBUG (MainThread) [custom_components.lightingsm.dining_room] Control Entities: ['light.chandelier_one']
2019-01-13 10:22:15 DEBUG (MainThread) [custom_components.lightingsm.dining_room] Added Control Entities as state entities: ['light.chandelier_one']
2019-01-13 10:22:15 DEBUG (MainThread) [custom_components.lightingsm.dining_room] Sensor Entities: [['binary_sensor.pir_living_two', 'binary_sensor.pir_living_three', 'binary_sensor.pir_stairs_up', 'binary_sensor.pir_stairs_down']]
2019-01-13 10:22:15 ERROR (MainThread) [homeassistant.setup] Error during setup of component lightingsm
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/setup.py", line 145, in _async_setup_component
hass, processed_config)
File "/config/custom_components/lightingsm.py", line 118, in async_setup
m = LightingSM(hass, config, machine)
File "/config/custom_components/lightingsm.py", line 141, in init
self.model = Model(hass, config, machine, self)
File "/config/custom_components/lightingsm.py", line 251, in init
self.config_sensor_entities(config)
File "/config/custom_components/lightingsm.py", line 586, in config_sensor_entities
event.async_track_state_change(self.hass, self.sensorEntities, self.sensor_state_change)
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/event.py", line 62, in async_track_state_change
entity_ids = tuple(entity_id.lower() for entity_id in entity_ids)
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/event.py", line 62, in
entity_ids = tuple(entity_id.lower() for entity_id in entity_ids)
AttributeError: 'NodeListClass' object has no attribute 'lower'

2.4.2 Startup Log files - question over constraints.

Hi Danny,

Please see below. I started HA at 9:30am local time; and it did detect it was inside the constraint period like it should.

It then adjusted that the FIRST_START callback is tomorrow at 7am. This makes sense as we've passed it already for today.

What I think might be a bug is the FIRST_END callback is also set for tomorrow; at 21:00. I would have suspected this should have been today? Or am I not following the logic of the callbacks correctly?

John

motion_master_bathroom:
   sensors: 
      - binary_sensor.master_bath_pir_sensor
   entities: 
      - light.master_vanity
   delay: 1800
   sensor_type_duration: True
   start_time: '07:00:00' 
   end_time: '21:00:00' 
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Initialising LightingSM entity with this configuration: OrderedDict([('sensors', ['binary_sensor.master_bath_pir_sensor']), ('entities', ['light.master_vanity']), ('delay', 1800), ('sensor_type_duration', True), ('start_time', '07:00:00'), ('end_time', '21:00:00'), ('name', 'motion_master_bathroom')])
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Entity name: motion_master_bathroom
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Control Entities: ['light.master_vanity']
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Added Control Entities as state entities: ['light.master_vanity']
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Sensor Entities: ['binary_sensor.master_bath_pir_sensor']
2019-01-15 09:30:45 INFO (MainThread) [custom_components.lightingsm.motion_master_bathroom] serivce data set up: OrderedDict([('sensors', ['binary_sensor.master_bath_pir_sensor']), ('entities', ['light.master_vanity']), ('delay', 1800), ('sensor_type_duration', True), ('start_time', '07:00:00'), ('end_time', '21:00:00'), ('name', 'motion_master_bathroom')])
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 7, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Parsed start time (unadjusted) 2019-01-15 07:00:00
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Parsed end time (unadjusted) 2019-01-15 21:00:00
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Setting FIRST START callback for 2019-01-16 07:00:00
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Setting FIRST END callback for 2019-01-16 21:00:00
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 7, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] now_is_between start time 2019-01-15 07:00:00.361415-05:00
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] now_is_between end time 2019-01-15 21:00:00.361415-05:00
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Config other
2019-01-15 09:30:45 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Using DAY MODE parameters: {'delay': 1800, 'service_data': None}

Exception Error while device is constrained

Version 2.2.2 will throw an exception as it seems to be trying to trigger a time constrained device.

2018-12-30 15:05:22 DEBUG (SyncWorker_0) [custom_components.lightingsm.motion_kitchen] Sensor state change: on
2018-12-30 15:05:22 DEBUG (SyncWorker_0) [custom_components.lightingsm.motion_kitchen] state: constrained
2018-12-30 15:05:22 DEBUG (SyncWorker_0) [custom_components.lightingsm.motion_kitchen] matches on
2018-12-30 15:05:22 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/lightingsm.py", line 329, in sensor_state_change
    self.sensor_on()
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 383, in trigger
    return self.machine._process(func)
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 1047, in _process
    return trigger()
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 251, in _trigger
    raise MachineError(msg)
transitions.core.MachineError: "Can't trigger event sensor_on from state constrained!"

Idea for another feature....

Currently the version 2.4.10 is working really well for me. It has eliminated a lot of complex automations that have always been a challenge to maintain. The wife acceptance factor is very high....

One shortcoming is that when someone turns on a light manually it goes into block mode. This makes sense. But to get it out of block mode takes the controlled entity (or state entity) to be turned off. This means if someone turns on a light it will stay in blocked mode and the light stays on until it's turned off manually or by another automation.

So I've setup some automations that if a light is on for XXX minutes it gets turned off. These work well.

But it would be a nice simplification if we had a "blocked_delay" feature that we could optionally set and after being blocked for that period of time it would turn off the controlled entity; resetting the blocked state.

This is nothing urgent or critical; but something nice to have to reduce further the complexity of having well automated lights.

Thanks again!

Feature: Define a timeout for blocked mode

I migrated recently form the VERA platform to HA (not fully yet). I use to use a Vera plugin called "SmartSwitch". It essentially did the same as what you have done here. The one key feature I do miss however is manual mode. It functions similarly to your "blocked" mode. in that when the switch was triggered manually, the auto timeout does not trigger. However it is somewhat more enhanced. It works in the following way:
Eh configured smartswitch not only has a "delay" value, but also a separate timeout (delay) for the manual override.. so the blocked mode remains active until the timeout is reached.... that way, you have more control over when a person switches a light on manually to eventually take back control. you can still get the indefinite "blocked" by setting the timeout to a very large value.

Think about it. Would be great to see this.

Regards
Tiaan

When exiting constrained mode if state entity is true should enter blocked mode?

Using 3.3.1.

When in constrained mode and the state entity is turned on and constraint ends I would expect to enter BLOCKED mode. But it seems IDLE is entered as it appears the state entity is disregarded.

Note: This is using state entity for state; and not the controlled entity.

So we are in IDLE mode but with the state entity being on!

Use case is a bathroom with 3 different lights in a group. That group is used as the state entity. Only the vanity lights in the control entity.

Will fail in upcoming 0.94 version of Homeassistant

This component fails to install in the current 0.94 beta releases due to not being able to install the transitions module. The REQUIREMENTS constant is no longer being used. the requirements now need to be specified in a manifest.json file similar to:

{
  "domain": "entity_controller",
  "name": "Entity Contoller",
  "documentation": "https://github.com/danobot/entity-controller/blob/master/README.md",
  "requirements": [
    "transitions==0.6.9"
  ],
  "dependencies": [
  ],
  "codeowners": ["@danobot"]
}

2.4.5 Sunset Constraint Issue

With sun constraints the callbacks are set in the past; causing continually reset/recreate. See log below.

Start time = Sunset
End_time = Sunrise

2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Entity name: motion_night_outdoor
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Control Entities: ['light.outdoor_sidedoor', 'light.outdoor_front', 'light.lower_patio_level']
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Added Control Entities as state entities: ['light.outdoor_sidedoor', 'light.outdoor_front', 'light.lower_patio_level']
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Sensor Entities: ['binary_sensor.single_garage_sensor', 'binary_sensor.dual_garage_sensor', 'binary_sensor.front_door_sensor', 'binary_sensor.mudroom_door_sensor', 'binary_sensor.basement_slider_sensor', 'binary_sensor.sun_slider_sensor', 'binary_sensor.sun_porch_sensor', 'binary_sensor.ring_front_door_ding', 'binary_sensor.ring_front_door_motion']
2019-01-16 15:00:58 INFO (MainThread) [custom_components.lightingsm.motion_night_outdoor] serivce data set up: OrderedDict([('sensors', ['binary_sensor.single_garage_sensor', 'binary_sensor.dual_garage_sensor', 'binary_sensor.front_door_sensor', 'binary_sensor.mudroom_door_sensor', 'binary_sensor.basement_slider_sensor', 'binary_sensor.sun_slider_sensor', 'binary_sensor.sun_porch_sensor', 'binary_sensor.ring_front_door_ding', 'binary_sensor.ring_front_door_motion']), ('entities', ['light.outdoor_sidedoor', 'light.outdoor_front', 'light.lower_patio_level']), ('delay', 600), ('sensor_type_duration', True), ('start_time', 'sunset'), ('end_time', 'sunrise'), ('name', 'motion_night_outdoor')])
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] --------------------------------------------------
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Time Dump
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] --------------------------------------------------
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] DT Now:               2019-01-16 15:00:58.545476-05:00
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] datetime Now:         2019-01-16 15:00:58.545575
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Next Sunrise:         2019-01-17 07:23:31-05:00
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Next Sunset:          2019-01-16 17:07:03-05:00
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Sunrise:              2019-01-15 07:23:31-05:00
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Sunset:               2019-01-15 17:07:03-05:00
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] --------------------------------------------------
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Sunset Diff (to now): 2:06:04.453583
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Sunrise Diff(to now): 2:06:04.453408
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] --------------------------------------------------
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Parsed start time (unadjusted) 2019-01-15 17:07:03
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Parsed end time (unadjusted) 2019-01-15 07:23:31
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Setting FIRST START callback for 2019-01-16 17:07:03
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Setting FIRST END callback for 2019-01-16 07:23:31
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] now_is_between start time 2019-01-16 17:07:03.547379-05:00
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] now_is_between end time 2019-01-17 07:23:31.547379-05:00
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Constrain period active. Scheduling transition to 'constrained'
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Config other
2019-01-16 15:00:58 DEBUG (MainThread) [custom_components.lightingsm.motion_night_outdoor] Using DAY MODE parameters: {'delay': 600, 'service_data': None}
2019-01-16 15:00:59 DEBUG (SyncWorker_0) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:00:59 DEBUG (SyncWorker_0) [custom_components.lightingsm.motion_night_outdoor] Exiting idle
2019-01-16 15:00:59 DEBUG (SyncWorker_0) [custom_components.lightingsm.motion_night_outdoor] Sensor state change: off
2019-01-16 15:00:59 DEBUG (SyncWorker_0) [custom_components.lightingsm.motion_night_outdoor] state: constrained
2019-01-16 15:00:59 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_night_outdoor] Sensor state change: off
2019-01-16 15:00:59 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_night_outdoor] state: constrained
2019-01-16 15:00:59 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_night_outdoor] Sensor state change: off
2019-01-16 15:00:59 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_night_outdoor] state: constrained
2019-01-16 15:00:59 DEBUG (SyncWorker_12) [custom_components.lightingsm.motion_night_outdoor] Sensor state change: off
2019-01-16 15:01:00 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:00 DEBUG (SyncWorker_12) [custom_components.lightingsm.motion_night_outdoor] state: constrained
2019-01-16 15:01:00 DEBUG (SyncWorker_1) [custom_components.lightingsm.motion_night_outdoor] Sensor state change: off
2019-01-16 15:01:00 DEBUG (SyncWorker_1) [custom_components.lightingsm.motion_night_outdoor] state: constrained
2019-01-16 15:01:00 DEBUG (SyncWorker_18) [custom_components.lightingsm.motion_night_outdoor] Sensor state change: off
2019-01-16 15:01:00 DEBUG (SyncWorker_18) [custom_components.lightingsm.motion_night_outdoor] state: constrained
2019-01-16 15:01:00 DEBUG (SyncWorker_13) [custom_components.lightingsm.motion_night_outdoor] Sensor state change: off
2019-01-16 15:01:00 DEBUG (SyncWorker_13) [custom_components.lightingsm.motion_night_outdoor] state: constrained
2019-01-16 15:01:01 DEBUG (SyncWorker_7) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:02 DEBUG (SyncWorker_12) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:03 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:04 DEBUG (SyncWorker_5) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:05 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:06 DEBUG (SyncWorker_17) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:07 DEBUG (SyncWorker_7) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:08 DEBUG (SyncWorker_0) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:09 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:10 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:11 DEBUG (SyncWorker_5) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:12 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:13 DEBUG (SyncWorker_2) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:14 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:15 DEBUG (SyncWorker_13) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:16 DEBUG (SyncWorker_7) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:17 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:18 DEBUG (SyncWorker_8) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:19 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:20 DEBUG (SyncWorker_16) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:21 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:22 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:23 DEBUG (SyncWorker_2) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:24 DEBUG (SyncWorker_12) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:25 DEBUG (SyncWorker_19) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:26 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:27 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:28 DEBUG (SyncWorker_7) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:29 DEBUG (SyncWorker_1) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:30 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:31 DEBUG (SyncWorker_7) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:32 DEBUG (SyncWorker_12) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:33 DEBUG (SyncWorker_16) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:34 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:35 DEBUG (SyncWorker_5) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:36 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:37 DEBUG (SyncWorker_19) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:38 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:39 DEBUG (SyncWorker_12) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:40 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:41 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:42 DEBUG (SyncWorker_1) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31
2019-01-16 15:01:43 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_night_outdoor] END TIME CALLBACK. New callback set to 2019-01-16 07:23:31

Feature Request - option to disable motion trigger during timeout

I have a camera as motion sensor that turns on a lamp when motion is detected. The problem is that the light from the lamp can be seen by the camera, so I get stuck in an endless loop where the light turning off triggers the motion again.

Therefore it would be great with an option that could define a number of seconds where motion is ignored around the turning-off.

2.4.7. start time stop time not working

Same configuration: now its time 11:12,
the lightingsm with start time 17:00:00 and stop time 23:59:59 is working correctly (it stays constrained).
The lightingsm with start time 00:00:01 and stop time 07:00:00 is not working correcltly (entity turns on while should be constrained)

EDIT relevant debug

Wrong date, tomorrow/today instead of today /today

2019-01-17 02:51:10 DEBUG (MainThread) [custom_components.lightingsm.dining_room_night] Setting FIRST START callback for 2019-01-18 00:00:01
2019-01-17 02:51:10 DEBUG (MainThread) [custom_components.lightingsm.dining_room_night] Setting FIRST END callback for 2019-01-17 07:00:00


dining_room_evening: 
    sensors: 
          - binary_sensor.pir_living_two
          - binary_sensor.pir_living_three
          - binary_sensor.pir_stairs_up
          - binary_sensor.pir_stairs_down
    entities: 
          - light.chandelier_one
          - light.chandelier_two 
          - light.chandelier_three 
    start_time: '17:00:00'   # change to sunset the day it will work
    end_time: '23:59:59'
    delay: 360
    sensor_type_duration: True
    overrides:
          - input_boolean.motion_dinimg_evening

  dining_room_night: 
    sensors: 
          - binary_sensor.pir_living_two
          - binary_sensor.pir_living_three
          - binary_sensor.pir_stairs_up
          - binary_sensor.pir_stairs_down
    entity: light.chandelier_one 
    service_data:
            brightness: 80
    start_time: '00:00:01'
    end_time: '07:00:00'
    delay: 65
    sensor_type_duration: True
    overrides:
          - input_boolean.motion_dinimg_night



2019-01-17 11:12:35 DEBUG (SyncWorker_7) [custom_components.lightingsm.dining_room_evening] Sensor state change: on
2019-01-17 11:12:35 DEBUG (SyncWorker_12) [custom_components.lightingsm.dining_room_night] Sensor state change: on
2019-01-17 11:12:35 DEBUG (SyncWorker_7) [custom_components.lightingsm.dining_room_evening] state: constrained
2019-01-17 11:12:35 DEBUG (SyncWorker_12) [custom_components.lightingsm.dining_room_night] state: idle
2019-01-17 11:12:35 INFO (SyncWorker_12) [custom_components.lightingsm.dining_room_night] <state light.chandelier_one=off; min_mireds=153, max_mireds=500, friendly_name=Chandelier two, supported_features=63 @ 2019-01-17T11:09:02.265155+01:00>
2019-01-17 11:12:35 DEBUG (SyncWorker_12) [custom_components.lightingsm.dining_room_night] State entities are OFF.
2019-01-17 11:12:35 DEBUG (SyncWorker_12) [custom_components.lightingsm.dining_room_night] Exiting idle
2019-01-17 11:12:35 DEBUG (SyncWorker_12) [custom_components.lightingsm.dining_room_night] Using DAY MODE parameters: {'delay': 65, 'service_data': OrderedDict([('brightness', 80)])}
2019-01-17 11:12:35 INFO (SyncWorker_12) [custom_components.lightingsm.dining_room_night] {'delay': 65, 'service_data': OrderedDict([('brightness', 80)])}
2019-01-17 11:12:35 DEBUG (SyncWorker_12) [custom_components.lightingsm.dining_room_night] light params before turning on: {'delay': 65, 'service_data': OrderedDict([('brightness', 80)])}
2019-01-17 11:12:35 DEBUG (SyncWorker_12) [custom_components.lightingsm.dining_room_night] Turning on light.chandelier_one with service parameters OrderedDict([('brightness', 80)])
2019-01-17 11:12:35 INFO (SyncWorker_10) [custom_components.lightingsm.dining_room_night] <state light.chandelier_one=on; min_mireds=153, max_mireds=500, brightness=80, hs_color=(38.88, 49.02), rgb_color=(255, 210, 129), xy_color=(0.447, 0.406), effect_list=['colorloop', 'random'], friendly_name=Chandelier two, supported_features=63 @ 2019-01-17T11:12:35.951685+01:00>
2019-01-17 11:12:35 DEBUG (SyncWorker_10) [custom_components.lightingsm.dining_room_night] State entities are ON. [light.chandelier_one]
2019-01-17 11:12:36 DEBUG (SyncWorker_15) [custom_components.lightingsm.dining_room_evening] Sensor state change: on
2019-01-17 11:12:36 DEBUG (SyncWorker_15) [custom_components.lightingsm.dining_room_evening] state: constrained
2019-01-17 11:12:36 DEBUG (SyncWorker_17) [custom_components.lightingsm.dining_room_night] Sensor state change: on
2019-01-17 11:12:36 DEBUG (SyncWorker_17) [custom_components.lightingsm.dining_room_night] state: active_timer
2019-01-17 11:12:36 DEBUG (SyncWorker_17) [custom_components.lightingsm.dining_room_night] Resetting timerFalse
2019-01-17 11:12:36 INFO (SyncWorker_17) [custom_components.lightingsm.dining_room_night] {'delay': 65, 'service_data': OrderedDict([('brightness', 80)])}
2019-01-17 11:12:47 INFO (SyncWorker_16) [custom_components.lightingsm.dining_room_night] <state light.chandelier_one=off; min_mireds=153, max_mireds=500, friendly_name=Chandelier two, supported_features=63 @ 2019-01-17T11:12:47.061841+01:00>
2019-01-17 11:12:47 DEBUG (SyncWorker_16) [custom_components.lightingsm.dining_room_night] State entities are OFF.
2019-01-17 11:12:47 DEBUG (SyncWorker_16) [custom_components.lightingsm.dining_room_night] Turning off entities, cancelling timer
2019-01-17 11:12:47 DEBUG (SyncWorker_16) [custom_components.lightingsm.dining_room_night] Turning off light.chandelier_one
2019-01-17 11:12:47 DEBUG (SyncWorker_16) [custom_components.lightingsm.dining_room_night] Entering idle
2019-01-17 11:12:47 DEBUG (SyncWorker_16) [custom_components.lightingsm.dining_room_night] Resetting state

2.3.0: Can't trigger event enable from state idle

It seems something causing these errors at the bottom came in with 2.3.0.

Error doing job: Exception in callback async_track_point_in_utc_time.<locals>.point_in_time_listener(<Event time_c....002364-05:00>) at /srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/event.py:195
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/event.py", line 211, in point_in_time_listener
    hass.async_run_job(action, now)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py", line 327, in async_run_job
    target(*args)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/event.py", line 179, in utc_converter
    hass.async_run_job(action, dt_util.as_local(utc_now))
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py", line 327, in async_run_job
    target(*args)
  File "/home/homeassistant/.homeassistant/custom_components/lightingsm.py", line 696, in constrain_end
    self.enable()
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 383, in trigger
    return self.machine._process(func)
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/core.py", line 1047, in _process
    return trigger()
  File "/srv/homeassistant/lib/python3.6/site-packages/transitions/extensions/nesting.py", line 251, in _trigger
    raise MachineError(msg)
transitions.core.MachineError: "Can't trigger event enable from state idle!"

Light constraints not respected under 2.4.1

Lights involved in the config pasted below came on at 11:44pm and 5:15am when the bathroom was used.

motion_master_bathroom:
   sensors: 
      - binary_sensor.master_bath_pir_sensor
   entities: 
      - light.master_vanity
   delay: 1800
   sensor_type_duration: True
   start_time: '07:00:00' 
   end_time: '21:30:00' 
2019-01-12 21:30:00 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Constrain Start reached. Disabling ML:
2019-01-12 21:30:00 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Turning off entities, cancelling timer
2019-01-12 21:30:00 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Turning off light.master_vanity
2019-01-12 21:31:19 INFO (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=off; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-12T21:31:19.734690-05:00>
2019-01-12 21:31:19 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] State entities are OFF.
2019-01-12 21:31:19 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] Turning off entities, cancelling timer
2019-01-12 21:31:19 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] Turning off light.master_vanity
2019-01-12 21:31:19 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] Entering idle
2019-01-12 21:31:19 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] Resetting state
2019-01-12 21:33:45 DEBUG (SyncWorker_19) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: off
2019-01-12 21:33:45 DEBUG (SyncWorker_19) [custom_components.lightingsm.motion_master_bathroom] state: idle
2019-01-12 23:44:56 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: on
2019-01-12 23:44:56 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] state: idle
2019-01-12 23:44:56 INFO (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=off; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-12T21:31:19.734690-05:00>
2019-01-12 23:44:56 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] State entities are OFF.
2019-01-12 23:44:56 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] Exiting idle
2019-01-12 23:44:56 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] Using DAY MODE parameters: {'delay': 1800, 'service_data': None}
2019-01-12 23:44:56 INFO (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] {'delay': 1800, 'service_data': None}
2019-01-12 23:44:56 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] light params before turning on: {'delay': 1800, 'service_data': None}
2019-01-12 23:44:56 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] Turning on light.master_vanity (no parameters passed to service call)
2019-01-12 23:45:44 INFO (SyncWorker_19) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=on; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-12T23:45:44.869571-05:00>
2019-01-12 23:45:44 DEBUG (SyncWorker_19) [custom_components.lightingsm.motion_master_bathroom] State entities are ON. [light.master_vanity]
2019-01-12 23:48:27 DEBUG (SyncWorker_15) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: off
2019-01-12 23:48:27 DEBUG (SyncWorker_15) [custom_components.lightingsm.motion_master_bathroom] state: active_timer
2019-01-12 23:48:27 DEBUG (SyncWorker_15) [custom_components.lightingsm.motion_master_bathroom] is_timer_expired -> False
2019-01-13 00:07:44 DEBUG (SyncWorker_2) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: on
2019-01-13 00:07:44 DEBUG (SyncWorker_2) [custom_components.lightingsm.motion_master_bathroom] state: active_timer
2019-01-13 00:07:44 DEBUG (SyncWorker_2) [custom_components.lightingsm.motion_master_bathroom] Resetting timerFalse
2019-01-13 00:07:44 INFO (SyncWorker_2) [custom_components.lightingsm.motion_master_bathroom] {'delay': 1800, 'service_data': None}
2019-01-13 00:08:54 INFO (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=off; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-13T00:08:54.842443-05:00>
2019-01-13 00:08:54 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] State entities are OFF.
2019-01-13 00:08:54 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] Turning off entities, cancelling timer
2019-01-13 00:08:54 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] Turning off light.master_vanity
2019-01-13 00:08:54 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] Entering idle
2019-01-13 00:08:54 DEBUG (SyncWorker_10) [custom_components.lightingsm.motion_master_bathroom] Resetting state
2019-01-13 00:11:17 DEBUG (SyncWorker_2) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: off
2019-01-13 00:11:17 DEBUG (SyncWorker_2) [custom_components.lightingsm.motion_master_bathroom] state: idle
2019-01-13 05:14:59 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: on
2019-01-13 05:14:59 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] state: idle
2019-01-13 05:14:59 INFO (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=off; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-13T00:08:54.842443-05:00>
2019-01-13 05:14:59 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] State entities are OFF.
2019-01-13 05:14:59 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] Exiting idle
2019-01-13 05:14:59 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] Using DAY MODE parameters: {'delay': 1800, 'service_data': None}
2019-01-13 05:14:59 INFO (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] {'delay': 1800, 'service_data': None}
2019-01-13 05:14:59 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] light params before turning on: {'delay': 1800, 'service_data': None}
2019-01-13 05:14:59 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] Turning on light.master_vanity (no parameters passed to service call)
2019-01-13 05:14:59 INFO (SyncWorker_1) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=on; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-13T05:14:59.718638-05:00>
2019-01-13 05:14:59 DEBUG (SyncWorker_1) [custom_components.lightingsm.motion_master_bathroom] State entities are ON. [light.master_vanity]
2019-01-13 05:19:00 INFO (SyncWorker_16) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=off; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-13T05:19:00.646002-05:00>
2019-01-13 05:19:00 DEBUG (SyncWorker_16) [custom_components.lightingsm.motion_master_bathroom] State entities are OFF.
2019-01-13 05:19:00 DEBUG (SyncWorker_16) [custom_components.lightingsm.motion_master_bathroom] Turning off entities, cancelling timer
2019-01-13 05:19:00 DEBUG (SyncWorker_16) [custom_components.lightingsm.motion_master_bathroom] Turning off light.master_vanity
2019-01-13 05:19:00 DEBUG (SyncWorker_16) [custom_components.lightingsm.motion_master_bathroom] Entering idle
2019-01-13 05:19:00 DEBUG (SyncWorker_16) [custom_components.lightingsm.motion_master_bathroom] Resetting state
2019-01-13 05:21:36 DEBUG (SyncWorker_13) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: off
2019-01-13 05:21:36 DEBUG (SyncWorker_13) [custom_components.lightingsm.motion_master_bathroom] state: idle
2019-01-13 07:00:00 DEBUG (MainThread) [custom_components.lightingsm.motion_master_bathroom] Constrain End reached. Enabling ML:
2019-01-13 07:56:54 DEBUG (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: on
2019-01-13 07:56:54 DEBUG (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] state: idle
2019-01-13 07:56:54 INFO (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=off; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-13T05:19:00.646002-05:00>
2019-01-13 07:56:54 DEBUG (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] State entities are OFF.
2019-01-13 07:56:54 DEBUG (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] Exiting idle
2019-01-13 07:56:54 DEBUG (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] Using DAY MODE parameters: {'delay': 1800, 'service_data': None}
2019-01-13 07:56:54 INFO (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] {'delay': 1800, 'service_data': None}
2019-01-13 07:56:54 DEBUG (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] light params before turning on: {'delay': 1800, 'service_data': None}
2019-01-13 07:56:54 DEBUG (SyncWorker_4) [custom_components.lightingsm.motion_master_bathroom] Turning on light.master_vanity (no parameters passed to service call)
2019-01-13 07:57:03 INFO (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] <state light.master_vanity=on; friendly_name=Master Vanity Lights, supported_features=0, icon=mdi:water @ 2019-01-13T07:57:03.035928-05:00>
2019-01-13 07:57:03 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] State entities are ON. [light.master_vanity]
2019-01-13 08:02:50 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: off
2019-01-13 08:02:50 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] state: active_timer
2019-01-13 08:02:50 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] is_timer_expired -> False
2019-01-13 08:03:20 DEBUG (SyncWorker_8) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: on
2019-01-13 08:03:20 DEBUG (SyncWorker_8) [custom_components.lightingsm.motion_master_bathroom] state: active_timer
2019-01-13 08:03:20 DEBUG (SyncWorker_8) [custom_components.lightingsm.motion_master_bathroom] Resetting timerFalse
2019-01-13 08:03:20 INFO (SyncWorker_8) [custom_components.lightingsm.motion_master_bathroom] {'delay': 1800, 'service_data': None}
2019-01-13 08:23:00 DEBUG (SyncWorker_13) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: off
2019-01-13 08:23:00 DEBUG (SyncWorker_13) [custom_components.lightingsm.motion_master_bathroom] state: active_timer
2019-01-13 08:23:00 DEBUG (SyncWorker_13) [custom_components.lightingsm.motion_master_bathroom] is_timer_expired -> False
2019-01-13 08:33:20 DEBUG (Thread-7278) [custom_components.lightingsm.motion_master_bathroom] Sensor entities are OFF.
2019-01-13 08:33:20 DEBUG (Thread-7278) [custom_components.lightingsm.motion_master_bathroom] Sensor entities are OFF.
2019-01-13 08:33:20 DEBUG (Thread-7278) [custom_components.lightingsm.motion_master_bathroom] Turning off entities, cancelling timer
2019-01-13 08:33:20 DEBUG (Thread-7278) [custom_components.lightingsm.motion_master_bathroom] Turning off light.master_vanity
2019-01-13 08:33:20 DEBUG (Thread-7278) [custom_components.lightingsm.motion_master_bathroom] Entering idle
2019-01-13 08:33:20 DEBUG (Thread-7278) [custom_components.lightingsm.motion_master_bathroom] Resetting state

block_timeout stuck "active" unsupported timedelta

I have a few controllers that I am using block_timeout and each one eventually errors out and gets stuck at "active" - here is the most recent error.

2019-03-18 07:51:56 DEBUG (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] Sensor state change: on
2019-03-18 07:51:56 DEBUG (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] state: idle
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] <state light.living_room_light_level=off; node_id=61, value_index=0, value_instance=1, value_id=72057595066155009, friendly_name=Living Room Light, supported_features=33 @ 2019-03-18T03:40:56.905027-06:00>
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] <state light.kitchen_can_lights_level=off; node_id=13, value_index=0, value_instance=1, value_id=72057594260848641, friendly_name=Kitchen Can Lights, supported_features=1 @ 2019-03-18T03:40:49.984460-06:00>
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] <state light.island_lights_level=off; node_id=60, value_index=0, value_instance=1, value_id=72057595049377793, friendly_name=Island Lights, supported_features=1 @ 2019-03-18T03:40:56.818885-06:00>
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] <state light.dining_lights_level=off; node_id=59, value_index=0, value_instance=1, value_id=72057595032600577, friendly_name=Dining Lights, supported_features=33 @ 2019-03-18T03:40:56.558182-06:00>
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] <state light.living_room_light_level=off; node_id=61, value_index=0, value_instance=1, value_id=72057595066155009, friendly_name=Living Room Light, supported_features=33 @ 2019-03-18T03:40:56.905027-06:00>
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] <state light.kitchen_can_lights_level=off; node_id=13, value_index=0, value_instance=1, value_id=72057594260848641, friendly_name=Kitchen Can Lights, supported_features=1 @ 2019-03-18T03:40:49.984460-06:00>
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] <state light.island_lights_level=off; node_id=60, value_index=0, value_instance=1, value_id=72057595049377793, friendly_name=Island Lights, supported_features=1 @ 2019-03-18T03:40:56.818885-06:00>
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] <state light.dining_lights_level=off; node_id=59, value_index=0, value_instance=1, value_id=72057595032600577, friendly_name=Dining Lights, supported_features=33 @ 2019-03-18T03:40:56.558182-06:00>
2019-03-18 07:51:56 DEBUG (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] State entities are OFF.
2019-03-18 07:51:56 DEBUG (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] Exiting idle
2019-03-18 07:51:56 DEBUG (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] Using DAY MODE parameters: {'delay': None, 'service_data': None, 'service_data_off': None}
2019-03-18 07:51:56 INFO (SyncWorker_65) [custom_components.entity_controller.kitchen_living_room_lights] {'delay': None, 'service_data': None, 'service_data_off': None}
2019-03-18 07:51:56 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/entity_controller/__init__.py", line 366, in sensor_state_change
    self.sensor_on()
  File "/usr/local/lib/python3.7/site-packages/transitions/core.py", line 383, in trigger
    return self.machine._process(func)
  File "/usr/local/lib/python3.7/site-packages/transitions/core.py", line 1047, in _process
    return trigger()
  File "/usr/local/lib/python3.7/site-packages/transitions/extensions/nesting.py", line 254, in _trigger
    return self._process(event_data)
  File "/usr/local/lib/python3.7/site-packages/transitions/core.py", line 409, in _process
    if trans.execute(event_data):
  File "/usr/local/lib/python3.7/site-packages/transitions/extensions/nesting.py", line 210, in execute
    return _super(NestedTransition, self).execute(event_data)
  File "/usr/local/lib/python3.7/site-packages/transitions/core.py", line 263, in execute
    self._change_state(event_data)
  File "/usr/local/lib/python3.7/site-packages/transitions/extensions/nesting.py", line 221, in _change_state
    dest_state.enter_nested(event_data, lvl)
  File "/usr/local/lib/python3.7/site-packages/transitions/extensions/nesting.py", line 178, in enter_nested
    self.enter(event_data)
  File "/usr/local/lib/python3.7/site-packages/transitions/core.py", line 120, in enter
    event_data.machine.callback(handle, event_data)
  File "/usr/local/lib/python3.7/site-packages/transitions/core.py", line 1005, in callback
    func(*event_data.args, **event_data.kwargs)
  File "/config/custom_components/entity_controller/__init__.py", line 551, in on_enter_active
    self._start_timer()
  File "/config/custom_components/entity_controller/__init__.py", line 423, in _start_timer
    expiry_time = datetime.now() + timedelta(seconds=self.previous_delay)
TypeError: unsupported type for timedelta seconds component: NoneType

Feature request, or how to add a Lux sensor?

I would like to achieve the following:
At night time turn on light with motion (easy with the component).
At day turn on light with motion if lux level is below a certain level. This I don't know the best way to achieve.

My lux sensor (is inside the motion sensor, a Xiaomi Aqara) gives a Lux value and also has an attribute Dark (true or false i think trigger at a value of 5 or so), and an attribute On (no idea for what is that)

Any advice?

2.4.3 constraints update incorrect

At 9pm the constraint went active. But it seems the end time is continuously updated to the same time it started.

See logs below:

2019-01-15 18:19:14 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_master_bathroom] State entities are OFF.
2019-01-15 18:19:14 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_master_bathroom] Turning off entities, cancelling timer
2019-01-15 18:19:14 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_master_bathroom] Turning off light.master_vanity
2019-01-15 18:19:14 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_master_bathroom] Entering idle
2019-01-15 18:19:14 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_master_bathroom] Resetting state
2019-01-15 18:21:54 DEBUG (SyncWorker_15) [custom_components.lightingsm.motion_master_bathroom] Sensor state change: off
2019-01-15 18:21:54 DEBUG (SyncWorker_15) [custom_components.lightingsm.motion_master_bathroom] state: idle
2019-01-15 21:00:00 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:00 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:00 DEBUG (SyncWorker_6) [custom_components.lightingsm.motion_master_bathroom] Exiting idle
2019-01-15 21:00:01 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:01 DEBUG (SyncWorker_9) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:02 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:02 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:03 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:03 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:04 DEBUG (SyncWorker_12) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:04 DEBUG (SyncWorker_12) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:05 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:05 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:06 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:06 DEBUG (SyncWorker_3) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:07 DEBUG (SyncWorker_18) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:07 DEBUG (SyncWorker_18) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:08 DEBUG (SyncWorker_7) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:08 DEBUG (SyncWorker_7) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:09 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:09 DEBUG (SyncWorker_14) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:10 DEBUG (SyncWorker_5) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}
2019-01-15 21:00:10 DEBUG (SyncWorker_5) [custom_components.lightingsm.motion_master_bathroom] END TIME CALLBACK. New callback set to 2019-01-15 21:00:00
2019-01-15 21:00:11 DEBUG (SyncWorker_11) [custom_components.lightingsm.motion_master_bathroom] Result of parsing: {'datetime': datetime.datetime(2019, 1, 15, 21, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'sun': None, 'offset': 0}

I added a code patch from what you added in 2.4.3 as follows to see if it solves it by incrementing the date:

   def end_time_callback(self, evt):
        """
            Called when `end_time` is reached, will change state to `constrained` and schedule `start_time` callback.
        """

        # must be reparsed to get up to date sunset/sunrise times
        parsed_end = self.parse_datetime(self.end_time)

        now = self.make_naive(dt.now())
        if parsed_end <= now:
            parsed_end += timedelta(1)  # (1)
       
        self.log.debug("END TIME CALLBACK. New callback set to %s", parsed_end)
        self.end_time_event_hook = event.async_track_point_in_time(
            self.hass, self.end_time_callback, parsed_end)
        self.update(end_time=parsed_end)
        # must be down here to make sure new callback is set regardless of exceptions
        self.constrain()

    def start_time_callback(self, evt):
        """
            Called when `start_time` is reached, will change state to `idle` and schedule `end_time` callback.
        """

        # must be reparsed to get up to date sunset/sunrise times
        parsed_start = self.parse_datetime(self.start_time)

        now = self.make_naive(dt.now())
        if parsed_start <= now:
            parsed_start += timedelta(1)  # start time is tomorrow!

        self.log.debug("START TIME CALLBACK."
                       " New callback set to %s", parsed_start)
        self.start_time_event_hook = event.async_track_point_in_time(
            self.hass, self.start_time_callback, parsed_start)

        self.update(start_time=parsed_start)
        self.enable()


How to pass a service_parameter that is templated?

Hi, running 2.2.9 and working well! Thanks for getting this going! It's already removed a lot of complex automations.

One thing I am struggling with is in the past my automations for motion lights would use a brightness that was from a template sensor that monitored time of day and luminance to compute what the overall brightness should be. This was done as follows:

   - service: light.turn_on
      data_template:
        entity_id: light.foobar
        brightness_pct: >-
          {{ states('sensor.target_brightness_inside')|int}}

How would I achieve this using the service parameters exposed by LightingSM?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.