Google Calendar Event component and AppDaemon strange behavior

I’ve been using the Google Calendar component to automate some switches in my house (to turn humidifiers on for the night in two rooms) and it’s all working fine. Not being able to leave anything alone, I have tried to redo the automations in AppDaemon instead of in yaml. As a result, I’ve found some strange behaviors which I’m not sure are in the GCal component, or on the AppDaemon side.

First, here’s my relevant setup:

the configuration.yaml bit is trivial:

google:
  client_id: !secret google_client_id
  client_secret: !secret google_client_secret

In google_calendars.yaml, the relevant bit is:

- cal_id: [email protected]
  entities:
  - device_id: all_entries
    ignore_availability: true
    name: All Calendar Schedule Entries
    track: true

(for the yaml based automations, I set up separate device_id entries to search for specific titles, but for the AppDaemon version I’m just looking at the all_entries feed and selecting in the code)

Now, I have two gcal events set up: HumidifierM runs 10:30pm to 8:00am nightly, and HumidifierK runs from 8:30pm to 6am nightly. Both are set on daily repeat, both appear to have identical setups except the title and times. That particular google calendar has no other events at all, it’s only for automation.

Currently, the AppDaemon just looks at all state change events fired by calendar.all_entries and logs them for me, including some of the info in the event object. I’m looking at the logs, and finding two anomalous behaviors.

First, while I expect any given state change event to be either from “on” to “off” or “off” to “on”, I am getting quite a few events each day that are “off” to “off” (I’ve not yet seen an “on” to “on” event). While these are easy to ignore programmatically, the fact that they happen at all is kind of odd to me. I suspect this is an issue on the gcal component side, but not sure.

Second, while the events for HumidifierK happen correctly, events for HumidifierM don’t. For example, for HumidifierK, which is on the 8:30pm to 6am cycle, I see every night at 20:30 that it correctly sees and “off” to “on” transition, and correctly sees that the end time in the event is 6am. But no event is fired at all at 22:30 , when HumidifierM should start, and instead I get an event firing at 06:08 (6:08 am) which says that it’s an “off” to “on” transition for HumidifierM, and has the correct end time of 08:00. But there’s nothing on the google calendar at 6:08. This feels like an AppDaemon side issue, since the same calendar successfully drives yaml integrations.

I have no idea if the two issues are related.
Thanks.

listen_state reports changes in attributes as well as the main state. If you just want to call the callback on the main state, you can specify that in the listen_state call

self.listen_state((self.motion, sensor, new = "on", old="off")

It is hard to say about your second problem without some actual code and logs showing the events happening, but obviously if no event is sent by HA, then AD can’t react.

Edit:
I find it quite useful having a log routine that prints all events when trying to figure out what events I am missing

self.listen_event(self.log_event)

calls log_event for every event received, and then have log_event print out the name of the event.

1 Like

The code you provided resolved that issue, thanks.

No more weird state change events. And I think I figured out the other issue, at least the source of it - when two events overlap, the calendar state remains “on” - it doesn’t handle overlapping events well. Need to get more info on how that’s handled properly.

1 Like