Not really sure if this is an AppDaemon issue or a google calendar component issue (leaning to the latter), but I have a situation where in AppDaemon a callback is registered to fire on state change using listen_state()
, but when the event fires, both old state and new state are off
. Now, it should be off at that time, but there shouldn’t be a state change?
Here’s the relevant code from google_calendars.yaml:
- cal_id: [email protected]
entities:
- device_id: all_entries
ignore_availability: true
name: All Calendar Schedule Entries
track: true
- device_id: Outdoor_Holiday_1
track: true
ignore_availability: true
name: Outdoor Holiday Lights Schedule 1
search: "#Holiday1"
There are several more entities with other search terms, but right now I’m only looking at the all_entries calendar. I have the following app_daemon code:
import appdaemon.plugins.hass.hassapi as hass
class GCalOnOff(hass.Hass):
def initialize(self):
self.log("Starting GCal Setup for: {} with search string: {}".format(self.friendly_name(self.args["calendar"]), self.args["search_string"]))
self.listen_state(self.Callback_On_State_Change, self.args["calendar"])
def Callback_On_State_Change(self, entity, attribute, old, new, kwargs):
self.log("Entered Callback_On_State_Change")
self.log("{} triggered an event. Old state: {} New state:{} Attribute: {} kwargs: {} args: {}".format(self.friendly_name(entity), old, new, attribute, kwargs,self.args))
With “all_entries” passed in as an argument, I get the following occasional entry in the log:
2018-11-27 07:44:18.596099 INFO master_humidifier: All Calendar Schedule Entries triggered an event. Old state: off New state:off Attribute: state kwargs: {'handle': UUID('2c280a1f-6770-4050-9ed1-3f0a3abb1021')} args: {'module': 'gcal', 'class': 'GCalOnOff', 'calendar': 'calendar.all_entries', 'search_string': 'HumidifierM', 'device': 'switch.aeotec_zw096_smart_switch_6_switch'}
2018-11-27 07:44:18.596524 INFO master_humidifier: Entity details for calendar.all_entries: {'entity_id': 'calendar.all_entries', 'state': 'off', 'attributes': {'message': 'HumidifierK', 'all_day': False, 'offset_reached': False, 'start_time': '2018-11-27 20:30:00', 'end_time': '2018-11-28 06:00:00', 'location': '', 'description': '', 'friendly_name': 'All Calendar Schedule Entries'}, 'last_changed': '2018-11-27T12:30:05.005545+00:00', 'last_updated': '2018-11-27T12:44:18.589024+00:00', 'context': {'id': '30ee9a7272df48c69a373a2251217b4c', 'user_id': None}}
2018-11-27 07:44:18.596973 INFO master_humidifier: message: HumidifierK End time: 2018-11-28 06:00:00
Note that the state change apparently fired at 7:44am, when there was no actual start or stop of a calendar event, and that both old state and new state are off
. The same kind of entry appeared at 16:48 the previous night, again, at a time when nothing should have changed.
Anyone have any idea what is causing this? I can filter for it with code, but it seems like some sort of bug…