Time & Date sensor is not updating

That’s weird.
As “it was working” and now isn’t (and given the complete reboots) it sounds like “something” literally changed the time zone of the OS.
What time zone do you live in ?

@petro sorry M8 you will probably be be better suited to help here, I’ve never come across an issue like this.

exactly, I don’t understand why suddenly it’s acting weird since yesterday. I live in India (+5:30 IST)
I’ve also checked my router (Xiaomi 3C) time and it was way back to 2018 and it’s synced now (no effects on hassio).

@petro really helped me with error logs, but couldn’t find anything in related with date & time.
Wanted to try fresh installation, but don’t want to admit my defeat. :wink:

I don’t think a fresh install is going to do anything. The problem has to lie in the component itself. Can you post your entire sensors.yaml file?

Sure,

# sensor 1:
  - platform: yr
  
# sensor 2:
  - platform: darksky
    api_key: !secret api_key
    latitude: !secret latitude
    longitude: !secret longitude
    units: auto
    name: Open Sky
    monitored_conditions:
      - summary
      - icon
      - wind_bearing
      - wind_speed
      - apparent_temperature
      - temperature
      - temperature_max
      - temperature_min
      - humidity
      - precip_probability
      - precip_type
      - cloud_cover
      - pressure


# sensor 3
  - platform: time_date
    display_options:
      - 'time_date'
      - 'time'
      - 'date'

# sensor 4
  - platform: systemmonitor
    resources:
    - type: memory_use_percent
    - type: swap_use_percent
    - type: processor_use
    - type: last_boot
    - type: disk_free
      arg: /home

# RPi Power Status
  - platform: rpi_power
    text_state: true

# CPU temperature
  - platform: command_line
    name: CPU Temperature
    command: 'cat /sys/class/thermal/thermal_zone0/temp'
    unit_of_measurement: "°C"
    value_template: '{{ (value | multiply(0.001)) | round(1) }}'

# Authenticated
  - platform: authenticated


  - platform: template
    sensors:
      template_pir_motion:
        friendly_name: 'Last Motion Location'
        value_template: >
                    {%- set pirs = [states.binary_sensor.bedroom_pir, states.binary_sensor.kidsroom_pir, states.binary_sensor.kitchen_pir] %}
                    {% for pir in pirs %}
                      {% if as_timestamp(pir.last_changed) == as_timestamp(pirs | map(attribute='last_changed') | max) %}
                        {{ pir.name }}
                      {% endif %}
                    {% endfor %}

  - platform: template
    sensors:
      since_last_motion:
        friendly_name: 'Minutes since last motion'
        entity_id: sun.sun
        value_template: >
          {%- set sensors = [states.binary_sensor.bedroom_pir, states.binary_sensor.kidsroom_pir, states.binary_sensor.kitchen_pir] %}
          {%- set filtered_sensors = sensors | selectattr('last_changed','==', sensors | map(attribute='last_changed') | max) | list %}
          {{ (( as_timestamp(now()) - as_timestamp(filtered_sensors[0].last_changed)) / 60 ) | int }}


# sensor #
#  - platform: speedtest
#    monitored_conditions:
#    - ping
#    - download
#    - upload

I’ve disabled speedtest as it’s using max RAM and bumping up my SWAP space.

Well that looks good.

Have you tried commenting it out, and restarting. Then un-commenting it out, and restarting?

yes, tried yesterday. It just makes the time sensor disappeared, but system time remains the same

Ok, I’m stumped. I don’t see how the integration can be not-working but also not produce warning, error, or debug statements saying why it’s not working.

As a side note, the system time does not depend on this integration. It just takes the system time and gives uses a sensor to display/use the time. So looking at logger page times and times in other areas has no bearing on the integration.

After you point out those "ERROR"s, I’ve checked them all and cleared them. Now I’m not getting anything like ERROR (all upper case - assuming them major errors). But I have many “Errors”(with lower case letters) with many integration that I don’t use or never heard them and not checked them all as they’re more than 600 results in search. I’ll take some time and check them. It must be logged somewhere buried in that.

They are probably python errors. which is what we are looking for. I don’t recall if you’ve said this, but are you running Hassio or home assistant in venv?

Hassio (pity on myself) as I wanted HA to work without much config.

unbelievable! It FIXED ITSELF just like that. I don’t know how! Time and date both are correct. It’s a bit cheerful and disappointment as I don’t know what’s wrong before.

Just checking log file in Config folder and observed it’s size is big and too many similar logs and wanted to restart to check logs from start. After that it shows right time.

Don’t know what fixed this time. But I’ve observed few logs I haven’t noticed before. Searched with term “time_date” but I don’t recall I’ve seen below logs before.

2020-01-22 21:01:56 INFO (SyncWorker_13) [homeassistant.loader] Loaded time_date from homeassistant.components.time_date
2020-01-22 21:02:00 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.time_date, old_state=None, new_state=<state sensor.time_date=21:02, 2020-01-22; friendly_name=Time & Date, icon=mdi:calendar-clock @ 2020-01-22T21:02:00.261842+05:30>>
2020-01-22 21:02:25 DEBUG (SyncWorker_8) [homeassistant.util.json] JSON file not found: /usr/src/homeassistant/homeassistant/components/time_date/.translations/sensor.en.json
2020-01-22 21:03:01 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2978636272] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=sensor.time_date, old_state=<state sensor.time_date=21:02, 2020-01-22; friendly_name=Time & Date, icon=mdi:calendar-clock @ 2020-01-22T21:02:00.261842+05:30>, new_state=<state sensor.time_date=21:03, 2020-01-22; friendly_name=Time & Date, icon=mdi:calendar-clock @ 2020-01-22T21:03:01.004957+05:30>>}

Are these normal?

Yeah those are debug statements. Those are normal. You can turn off debug by setting your logging to ‘info’.

Sure.
Thank you for your help. :smiley:

No problem, now you have a cleaner log too without those errors :wink:

Should I require info level logs? I mean, they are pretty common for all systems and don’t need our attention right? Just wanted to reduce my SD card wear level.

Personally, I run my logs like this:

  default: error
  logs:
    requests.packages.urllib3.connectionpool: critical 
    py.warnings: critical

This will only show you errors. Or critical issues.

I only get 2 lines at startup and only errors. My logs are pretty emtpy for the most part.

got the idea. Thanks :slightly_smiling_face:

Hello,
after update from 0.114.4 to 0.115.3 is template with time sensor not updated.

I have following sensor:

- platform: time_date
  display_options:
    - 'time'
    - 'date'

- platform: template
  sensors:
    date_custom:
      friendly_name: Datum
      entity_id: sensor.time
      value_template: "{{ now().strftime('%A %d.%m.%Y %H:%M') }}"

In version 0.114.4 is time updated:
Time 0.114.4

In version 0.115.3 is time same as HA start and no more updated
Time 0.115.3

I din’t find info that there is breaking change for this component for version 0.115
Has anybody same issue?

entity_id is deprecated, it is in the breaking changes for templates. You’ll have to use sensor.time inside your template. for a quick fix

- platform: template
  sensors:
    date_custom:
      friendly_name: Datum
      value_template: >
        {% set dump = states('sensor.time') %}
        {{ now().strftime('%A %d.%m.%Y %H:%M') }}
1 Like

or use the new as_local() version:

{{as_local(states.sensor.time.last_updated).strftime('%A %d.%m.%Y %H:%M')}}

which is a bit more difficult to find, but described here, though admitted, not very clearly.

replace any now() with as_local(states.sensor.time.last_updated) or sensor.date for that matter, if you want to only update it once a day.