slashback100 / presence_simulation

Home Assistant Presence Simulation
423 stars 22 forks source link

Presence simulation selecting "unavailable" state #37

Closed pannal closed 2 years ago

pannal commented 2 years ago

Hey,

Thank you for this great idea. I've been trying the script and I've noticed that it only or mostly seems to honor "off" states; it also seems to honor "unavailable" states, which I wouldn't expect:

2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Entity light.lampe_esstisch
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Entity light.lampe_esstisch_ambilight
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Entity light.lampe_tv
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Entity light.lichtbuero1
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Entity light.lichtbuero2
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Entity switch.plug1_2
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] All async tasks launched
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.lampe_esstisch
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lampe_esstisch', 'state': 'off', 'attributes': {'min_mireds': 153, 'max_mireds': 370, 'effect_list': ['Slow Temp', 'Stop'], 'supported_color_modes': ['color_temp'], 'flowing': False, 'music_mode': False, 'night_light': False, 'friendly_name': 'Lampe Esstisch', 'supported_features': 44}, 'last_changed': '2021-09-28T16:04:56.849666+00:00', 'last_updated': '2021-09-28T16:04:56.849666+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lampe_esstisch foreseen at 2021-10-05 16:04:56.849666+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.lampe_esstisch to off
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lampe_esstisch', 'state': 'unavailable', 'attributes': {'min_mireds': 153, 'max_mireds': 370, 'effect_list': ['Slow Temp', 'Stop'], 'supported_color_modes': ['color_temp'], 'friendly_name': 'Lampe Esstisch', 'supported_features': 44}, 'last_changed': '2021-09-28T23:06:29.630296+00:00', 'last_updated': '2021-09-28T23:06:29.630296+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lampe_esstisch foreseen at 2021-10-05 23:06:29.630296+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.lampe_esstisch_ambilight
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lampe_esstisch_ambilight', 'state': 'off', 'attributes': {'min_mireds': 153, 'max_mireds': 588, 'effect_list': ['Strobe color', 'Police', 'Christmas', 'RGB', 'Random Loop', 'Fast Random Loop', 'LSD', 'Slowdown', 'Night Mode', 'Date Night', 'Movie', 'Sunrise', 'Sunset', 'Romance', 'Happy Birthday', 'Disco', 'Strobe epilepsy!', 'Alarm', 'Police2', 'WhatsApp', 'Facebook', 'Twitter', 'Home', 'Candle Flicker', 'Slow Temp', 'Stop'], 'supported_color_modes': ['color_temp', 'hs', 'rgb'], 'flowing': False, 'music_mode': False, 'night_light': False, 'friendly_name': 'Lampe Esstisch ambilight', 'supported_features': 44}, 'last_changed': '2021-09-28T16:04:56.849666+00:00', 'last_updated': '2021-09-28T16:04:56.849666+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lampe_esstisch_ambilight foreseen at 2021-10-05 16:04:56.849666+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.lampe_esstisch_ambilight to off
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lampe_esstisch_ambilight', 'state': 'unavailable', 'attributes': {'min_mireds': 153, 'max_mireds': 588, 'effect_list': ['Strobe color', 'Police', 'Christmas', 'RGB', 'Random Loop', 'Fast Random Loop', 'LSD', 'Slowdown', 'Night Mode', 'Date Night', 'Movie', 'Sunrise', 'Sunset', 'Romance', 'Happy Birthday', 'Disco', 'Strobe epilepsy!', 'Alarm', 'Police2', 'WhatsApp', 'Facebook', 'Twitter', 'Home', 'Candle Flicker', 'Slow Temp', 'Stop'], 'supported_color_modes': ['color_temp', 'hs', 'rgb'], 'friendly_name': 'Lampe Esstisch ambilight', 'supported_features': 44}, 'last_changed': '2021-09-28T23:06:29.630364+00:00', 'last_updated': '2021-09-28T23:06:29.630364+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lampe_esstisch_ambilight foreseen at 2021-10-05 23:06:29.630364+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.lampe_tv
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lampe_tv', 'state': 'off', 'attributes': {'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['blink', 'breathe', 'okay', 'channel_change', 'finish_effect', 'stop_effect'], 'supported_color_modes': ['color_temp'], 'linkquality': 102, 'power_on_behavior': None, 'update': {'state': 'idle'}, 'update_available': False, 'friendly_name': 'Licht TV', 'supported_features': 47}, 'last_changed': '2021-09-28T16:04:56.849666+00:00', 'last_updated': '2021-09-28T16:04:56.849666+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lampe_tv foreseen at 2021-10-05 16:04:56.849666+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.lampe_tv to off
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lampe_tv', 'state': 'off', 'attributes': {'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['blink', 'breathe', 'okay', 'channel_change', 'finish_effect', 'stop_effect'], 'supported_color_modes': ['color_temp'], 'linkquality': 105, 'power_on_behavior': None, 'update': {'state': 'idle'}, 'update_available': False, 'friendly_name': 'Licht TV', 'supported_features': 47}, 'last_changed': '2021-09-28T13:48:25.560826+00:00', 'last_updated': '2021-09-28T16:53:29.139002+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lampe_tv foreseen at 2021-10-05 16:53:29.139002+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.lichtbuero1
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lichtbuero1', 'state': 'off', 'attributes': {'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['blink', 'breathe', 'okay', 'channel_change', 'finish_effect', 'stop_effect'], 'supported_color_modes': ['color_temp'], 'linkquality': 87, 'power_on_behavior': None, 'update': {'state': 'idle'}, 'update_available': False, 'friendly_name': 'Licht Büro 1', 'supported_features': 47}, 'last_changed': '2021-09-28T16:04:56.849666+00:00', 'last_updated': '2021-09-28T16:04:56.849666+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lichtbuero1 foreseen at 2021-10-05 16:04:56.849666+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.lichtbuero1 to off
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lichtbuero1', 'state': 'on', 'attributes': {'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['blink', 'breathe', 'okay', 'channel_change', 'finish_effect', 'stop_effect'], 'supported_color_modes': ['color_temp'], 'color_mode': 'color_temp', 'brightness': 205, 'color_temp': 454, 'hs_color': [29.79, 84.553], 'rgb_color': [255, 146, 39], 'xy_color': [0.579, 0.388], 'linkquality': 87, 'power_on_behavior': None, 'update': {'state': 'idle'}, 'update_available': False, 'friendly_name': 'Licht Büro 1', 'supported_features': 47}, 'last_changed': '2021-09-28T16:48:43.360041+00:00', 'last_updated': '2021-09-28T16:48:43.360041+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lichtbuero1 foreseen at 2021-10-05 16:48:43.360041+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: light.lichtbuero2
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lichtbuero2', 'state': 'off', 'attributes': {'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['blink', 'breathe', 'okay', 'channel_change', 'finish_effect', 'stop_effect'], 'supported_color_modes': ['color_temp'], 'linkquality': 57, 'power_on_behavior': None, 'update': {'state': 'idle'}, 'update_available': False, 'friendly_name': 'Licht Büro 2', 'supported_features': 47}, 'last_changed': '2021-09-28T16:04:56.849666+00:00', 'last_updated': '2021-09-28T16:04:56.849666+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lichtbuero2 foreseen at 2021-10-05 16:04:56.849666+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switching light light.lichtbuero2 to off
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'light.lichtbuero2', 'state': 'off', 'attributes': {'min_mireds': 250, 'max_mireds': 454, 'effect_list': ['blink', 'breathe', 'okay', 'channel_change', 'finish_effect', 'stop_effect'], 'supported_color_modes': ['color_temp'], 'linkquality': 54, 'power_on_behavior': None, 'update': {'state': 'idle'}, 'update_available': False, 'friendly_name': 'Licht Büro 2', 'supported_features': 47}, 'last_changed': '2021-09-27T23:02:01.513485+00:00', 'last_updated': '2021-09-28T16:51:43.398260+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of light.lichtbuero2 foreseen at 2021-10-05 16:51:43.398260+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Simulate one entity: switch.plug1_2
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'switch.plug1_2', 'state': 'off', 'attributes': {'temperature': 36, 'model': 'chuangmi.plug.m3', 'friendly_name': 'BüroWiFiPlug1', 'icon': 'mdi:power-socket'}, 'last_changed': '2021-09-28T16:04:56.849666+00:00', 'last_updated': '2021-09-28T16:04:56.849666+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of switch.plug1_2 foreseen at 2021-10-05 16:04:56.849666+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switching entity switch.plug1_2 to off
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] State {'entity_id': 'switch.plug1_2', 'state': 'off', 'attributes': {'temperature': 38, 'model': 'chuangmi.plug.m3', 'friendly_name': 'BüroWiFiPlug1', 'icon': 'mdi:power-socket'}, 'last_changed': '2021-09-28T01:54:00.946302+00:00', 'last_updated': '2021-09-28T16:06:03.267118+00:00'}
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Switch of switch.plug1_2 foreseen at 2021-10-05 16:06:03.267118+00:00
2021-10-05 18:04:56 DEBUG (MainThread) [custom_components.presence_simulation] Presence simulation will be relaunched in 7 days

Did I just not wait long enough for it to show scheduled "on" states?

slashback100 commented 2 years ago

These are just the logs of the start of the Simulation. If all your lights were off 7 days ago at the same time, it will be off after simulation starts. I can see in your log that your light light.lichtbuero1 is supposed to be turned on at 2021-09-28T16:48:43.360041+00:00`. Did it?

pannal commented 2 years ago

OK, the off states seem right. I'm guessing when those trigger, the next ones will get queued.

The one I'm curious about is the "unavailable" state, though. Should this be a state a lamp/switch uses in this presence simulation?

slashback100 commented 2 years ago

The simulator won't actually do anything on this 'unavailable' state. In the method update_entity (in __init__.py), you see that the call to the service light.turn_on or off will be done only if the state of the entity to replicate is on of off. If it is neither on nor off, a debug message will be written in the log and the simulator will wait the next event.