Google Calendar OFF Event Message/Description

Hi, I have set up a Google Calendar and it shows, and my events sync as it should.

What I’m trying to do is create calendar appointments to control any switch in the house.

The easiest way I could figure out, was to use the appointment title for the entity name, and the message for the service to call.

My calendar appointment would look like:

Title: switch.test_heater
Description: switch.turn_ (Yes truncated, the on or off will come from the calendar event start and end triggers)

Here is my automation:

- id: '1559876102751'
  alias: Calendar Events Stop Start
  trigger:
  - entity_id: calendar.home_assistant
    platform: state
    from: 'off'
    to: 'on'
  - entity_id: calendar.home_assistant
    platform: state
    from: 'on'
    to: 'off'
  condition: []
  action:
  - data_template:
      entity_id: '{{states.calendar.home_assistant.attributes.message}}'
    service_template: '{{states.calendar.home_assistant.attributes.description}}{{states.calendar.home_assistant.state}}'

The above runs fine for turning ON my switch.

The problem is with the OFF trigger. It runs but it doesn’t run with the appointment details that is ending. It looks like it’s probably running with the NEXT appointment’s details (in my case, there is no next appointment, so things just break).

Log Details (ERROR)
Fri Jun 14 2019 07:50:10 GMT+1200 (New Zealand Standard Time)
Error while executing automation automation.calendar_events_stop_start. Invalid data for call_service 
at pos 1: Service Noneoff does not match format <domain>.<name>

You see that the Service is Noneoff. So it gets the off part from the event end, which is fine, but it doesn’t have the calendar appointments description value which should be switch.turn_.

Is this a bug with the calendar component?

I’d love to keep it this simple, where you just create events that are the duration of how long the switch should be on. That way I have a pretty good scheduler, and can easily set up schedules and pseudo-timers. I did think of having two appointments, one for turning on, and one for turning off. But that sucks.

(Also, c’mon, it’d be great to have a scan_interval parameter for the calendar component, instead of hard coding to 15 minutes. How do you force a calendar update? It’s damn hard work trying to set up and debug your automations if you have to wait for it…)

Cheers!

Bump? I’d really appreciate if anyone who is in the know with this can shed some light :slight_smile:

I’m not sure if it will work (I was actually watching this to see if any other guru gave you an answer because I was interested too…) but you could try this:

- id: '1559876102751'
  alias: Calendar Events Stop Start
  trigger:
  - entity_id: calendar.home_assistant
    platform: state
  condition: []
  action:
  - data_template:
      entity_id: '{{states.calendar.home_assistant.attributes.message}}'
    service_template: '{{states.calendar.home_assistant.attributes.description}}{{states.calendar.home_assistant.state}}'

My gut instinct tells me it won’t but you can try it to see.

From that error the issue might be because the calendar event doesn’t go to “off”. Instead the description goes to “none”.And that’s why it’s seeing “Noneoff” as the service call.

you will probably have to create a second automation to turn the switch off that looks at the calendar event for an indication that the event is over (maybe when description goes to “None”?) then call the switch.turn_off service. Or whatever the turn_off service is. I can’t really see how the entity_id from the service call above is a “switch”.

I’ve tried that too (leaving out the trigger details, just having a trigger).

The issue is that it triggers, but description like you said is None. The problem with that, is that we have no way of telling what the service is. This I’m guessing is the first issue. If we work through this, we’d probably also find a blank message by looking at the ‘next’ appointment details for when the event is ‘on’.

We need to change the plugin to hold on to the event data up until the event has stopped, not just until it has started.

Is there an easy way to start fiddling with the existing code in place for this? Or do I need to make a full copy of it into a new plugin? (e.g. just a .py file I can mess with directly somewhere?). I’m running hass.io through Ubuntu 16.04.

Thanks,

you can tell it explicitly what the service will be if you create a second automation.

I don’t think so.

you’ll have to create a custom version of the component and mess with it and then create a PR to get it accepted into the regular component or just keep it as custom.

Heh, the point of this is to have a single automation that handles everything happening in the calendar, e.g. switches, thermostats, etc… everything that does on off.

Or perhaps even putting JSON in the body of the appointment, to grab that out and do whatever you need to do.

If at all possible, I want to have a single calendar, single automation, single appointment that controls on and off.

Many people try to do tot much in a single automation, I agree, but it’d be great in this case to keep it super tidy and contained.

The issue is two automation approach won’t work I don’t think, because when it turns ‘off’ and I specify the service manually in the automation, I still don’t get the entity_id from the appointment OFF event. (since everything in the off event is blank)

I do have this working if I use two appointments, one for turning things on, and one for turning things off. But then you have to always create two appointments, which is a hassle.

I wish it was as easy as just opening a .py file and messing with it in there instead of setting up a whole dev env for this.

While I’m at it, I think I’ll also look at adding a config setting for scan interval, or perhaps something to just force refreshing. That’d make debugging and building automations a little easier.

Let me know if you get into this a bit more, and I’ll do the same.

I doubt I’ll do anything with it as I don’t have a use for it.

I was just trying to help you out and failed. :wink:

Heh non worries, and thanks for checking it out.

I’ll post back if I get anywhere with this.

It will be a perfect scheduler :slight_smile:

(Slightly off topic, how do people normally schedule lights on/off, etc based on times, that are easily configurable?)

Cheers,

You could hard code the times if you consistently want the time to be the same.

Or you could use something like an input_datetime so you can have it configurable from the front end (lovelace).