Hello.
Not sure if all HA components should follow the same rules, especially in order to maintain compatibility between each other.
Anyway recently I found in logs (v2021.12.9), timestamp sensor started to fail when receiving time copied directly from google calendar sensor.
The error is:
ValueError: Invalid datetime: sensor.waste_mixed provides state '2022-01-21 00:00:00', which is missing timezone information
And in fact this is how google data taken from google calendar looks like:
I can see 2 obvious things missing from data stored in google calendar entity attributes:
The date is not ISO formatted (missing T character between date and time parts). This missing is here for long time. Actually I was adding this T in order to be able to use that value in the sensor.
There is no timezone information. At this point I don’t know google API provides it, but I would be really surprised if not.
I didn’t find settings in google calendar integration page which allows to change those data.
Can you confirm I’m not missing anything and thus i should raise an issue to github?
TBH I’m not aware about breaking change released recently, making timestamp sensor fail unless timezone provided. I can see changes in templating, but I set the sensor using nodered, not using templates (unless NR uses templates to do so)
It should be fixed in google calendars if the attributes do not supply a timestamp, however what is creating sensor.waste_mixed?
The change is a bug if you see it in your logs unless it comes from a template. Then you should update your template. It’s listed in the Updates for custom integration developers section because users shouldn’t be seeing it as it’s a backend change that should be fixed in all integrations.
EDIT: Although you are getting a ValueError, probably should just post the full error as it is in the logs.
Thank you for instant response.
The sensor is created and set by NodeRed. Its flow takes value from mentioned google calendar entity and pastes it into new sensor
Looking into log I found even more details. Seems like sensor creation fails if time without TZ is provided:
2022-01-17 13:16:19 ERROR (MainThread) [homeassistant.util.logging] Exception in handle_entity_update when dispatching 'nodered_entity_6cdd0bc8.b8e434_84064076.f3b418': ({'type': 'nodered/entity', 'server_id': '6cdd0bc8.b8e434', 'node_id': '84064076.f3b418', 'state': '2022-01-21T00:00:00', 'attributes': {'cue': '4 days', 'cue_weekday': 'Fri'}, 'id': 130},)
Traceback (most recent call last):
File "/config/custom_components/nodered/__init__.py", line 135, in handle_entity_update
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _async_write_ha_state
state = self._stringify_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 511, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 411, in state
raise ValueError(
ValueError: Invalid datetime: sensor.waste_mixed provides state '2022-01-21 00:00:00', which is missing timezone information
Not sure such a traceback is expected. To me it looks like not early enough handed exception.
PS. You can see T in the state value, since I’m adding it explicitly. The original value from calendar sensor doesn’t contain that.
Yeah but it fails right now in 2021.12.9 In fact the sensor receives date/time data but in unexpected format (missing TZ). Maybe some changes leaked to the recently released version
if you remove device_class: timestamp it will work instantly. It’s because you’re setting that somewhere, it needs to have a datetime object for the state now.
msg.data.attributes.start_time comes directly from google calendar entity, and is not compliant with date time format rules. I know it’s attribute only, but still, IMO it should be ISO formatted incl. TZ.
I’m not aware about breaking change applied already to most recent HA version. The message you pased sais it will fail after 2022.2
I recently added Google calendars in to HA via the Google developer route. I checked the google_calendars.yaml file created in to my Configuration folder. However the issue that Im facing now is that my Calendars base time should be GMT and when I view the calendar entries they are displayed as my local time which at the moment is GMT+2. Is there a way to control the displace time used by the calendar by adding a line to the google_calendars.yaml
In the Lovelace card there is no apparent way to specify the time zone to be used for any calendar…
- cal_id: [email protected]
entities:
- device_id: charlie_school_events
ignore_availability: true
name: Charlie School Events
track: true
After some extensive testing, I think that this response of showing the local time-zone rather than the Google Calendar selected time-zone is caused by the Home Assistant Mobile app or the HA Calendar Card handling of time-zones.
I have set all my Google calendars to use my home time-zone of GMT as per the Google guidance documentation (Use Google Calendar in different time zones - Android - Calendar Help) I also changed the Android phone Google Calendars app to use the calendar’s time-zone by turning off the setting “use mobile time-zone”.
I have two viewing devices with me and I’m currently in a GMT+2 location. One is my personal laptop that still has GMT time and date set. The other is my mobile which has automatically switched over to GMT+2 being my current local time-zone. When I view my HA instance on my Laptop (still has GMT time) then all the Calendar times are correctly displayed as GMT. When I view my HA instance using the Android HA app then all times are adjusted to GMT+2 as the HA App is using the device local time rather than the actual HOME location time (GMT).
I have installed the Google Calendar API in to HA and then if I use the HA Calendar card it allows me to set up the card to display any calendar from my gmail account using the google_calendar.yaml config, select the opening view as ‘month’, ‘day’, ‘list’ but there is no option for displayed time-zone. As this is a HA integration of the Goolge API one might have expected the Calendar card to handle the displayed time-zone following the Google calendar guidelines obtained from the actual calendar time-zone settings as detailed in the link above. Unfortunately not.
If I share my calendar and then display using a http web card, then I can force it to display the calendar’s GMT time zone by amending the http address like so:
Notice I can also force the display by adding mode=AGENDA. However the HA calendar card is a cleaner looking card and I would rather be able to use that option but it doesn’t work for me when I’m regularly travelling outside of my home time-zone.
So in summary, I think that within Google calendar settings allows the user to select if calendars should be displayed in either the local client time or in the home time-zone. However the HA Calendar card does not seem to support this feature. In my above post I had asked if there is any way to set the calendar display time zone (similar to the method in the Web View Card, but I have so far not been able to find a method to do this by editing the google_calendars.yaml file as all methods which I tried so far result in an error generated in the notifications on a HA restart as being unsupported for google calendars.
Hopefully someone with more extensive knowledge of this might advise otherwise.