enkama / hass-variables

Home Assistant variables component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Still got an error initializing Timestamp variables.

sermayoral opened this issue · comments

#102 still persists in v3.3.8.

The problem occurs when you fill out this window:

imagen

Getting the following error and the variable unavailable:

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:507
Integration: Sensor (documentation, issues)
First occurred: 22:23:26 (1 occurrences)
Last logged: 22:23:26

Error adding entities for domain sensor with platform variable
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 743, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 843, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 784, in _async_generate_attributes
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 749, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 554, in state
    raise ValueError(
ValueError: Invalid datetime: sensor.date_mto_descalcificacion_cafetera provides state '2023-11-23 09:00:00', which is missing timezone information

If you leave "initial value" empty, it works.

Not sure if it's because you're in a different region so not sure if that may be the issue, but I cannot reproduce. First, are you sure you're running v3.3.8?

Can you please enable debug logging and post the logs when creating a new timestamp variable to see if they show anything that may help.

2023-11-24_18-27-05 908 2023-11-24_18-27-29 427 2023-11-24_18-27-48 943

You are completely right. I wasn't running v3.3.8. I thought i was. Very strange. Sorry :-(

An important fact. In my screenshots, the date format is dd/MM/yyyy instead of MM/dd/yyyy. It can be very confusing

Setting a value creating a new timestamp sensor doesn't crash anymore :-). Although the date you enter is in UTC, and then it is converted to your time zone:
imagen

My timezone is GMT+1:

imagen

It also happened in your screenshots, So I guess it's done on purpose.

Also, updating a timestamp sensor seems to have no effect

imagen

Last change and last update attributes change, but the state doesn't it:

imagen

Thanks

I just noticed that I think you are trying to update the value of an existing variable using the Configuration page. In general, that won't work. You need to call one of the Variable Services to update (variable.update_sensor). When I update a timestamp Variable Sensor using variable.update_sensor it updates for me.

2023-11-30_17-16-38 211 2023-11-30_17-16-50 976 2023-11-30_17-17-08 722

I'll still look to add a timezone selector when creating a new timestamp Variable Sensor but no eta on that.