Playstation 4 - History/Weekly Played Time

Hi All,

Recently my history/played time weekly was working until the last update, now it just shows - “Invalid Date”

I have the following setup…

      - platform: history_stats
        name: PS4 Played Time
        entity_id: media_player.playstation_4
        state: 'playing'
        type: time
        start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) -now().weekday() * 86400 }}'
        end: '{{ now() }}'

      - platform: template
        sensors:
            ps4_time_played:
           friendly_name: 'PS4 - Weekly Played Time'
           device_class: timestamp
           value_template: >-
              {{ states.sensor.ps4_played_time.attributes.value }}

When I look up the entities, they show up how I would expect…

However, when I actually put it into the UI with the following…

        - type: entity
          entity: sensor.ps4_time_played

It shows up like this:

I can click on the entity in the UI and it shows the proper time format.

image

I’m at a loss as to why all the sudden this changed after the last update to HA but that’s when it started to load oddly.

Any guidance or help would be greatly appreciated. It was nice to see the weekly timer before just to see how much usage it was getting.

Thank you for any help!

Remove the device_class: timestamp from the template sensor.
I have the same sensor that works, and adding the class to it, shows the same behavior.

1 Like

You the man! That did the trick! Thank you very much!

Hi, exactly how have you added this into your configuration?
I get errors at adding.

you’d have to share your config. His yaml is correct and that means you aren’t adjusting it for your environment. I.e. you have too many or too few spaces or you’re placing it in the wrong spot.

Added this in sensor.yaml:

####  PS4 integration ###########################
- platform: history_stats
  name: PS4 Played Time
  entity_id: media_player.playstation_4
  state: 'playing'
  type: time
  start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) -now().weekday() * 86400 }}'
  end: '{{ now() }}'

- platform: template
  sensors:
      ps4_time_played:
      friendly_name: 'PS4 - Weekly Played Time'
      value_template: >-
         {{ states.sensor.ps4_played_time.attributes.value }}

resulting in :
Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data[‘sensors’][‘friendly_name’]. Got ‘PS4 - Weekly Played Time’
expected a dictionary for dictionary value @ data[‘sensors’][‘ps4_time_played’]. Got None
expected a dictionary for dictionary value @ data[‘sensors’][‘value_template’]. Got ‘{{ states.sensor.ps4_played_time.attributes.value }}’. (See ?, line ?).

remove 2 spaces before this line.

No more errors. Great!
Thanks a lot.
Now test if it gives the expected results…

@petro: I do not get any data in. So nothing to show. Do I miss anything in connecting the PS4?

Well you need playstation 4 as a media_player. This is just getting time played/used. I have no idea what integration @bbalz is using. I’d assume the playstation integration.

Yes, that’s the integration.

I no longer have it in home assistant myself though. I had no automations setup for the PS4 as I don’t really play it at all. Also I don’t really look at the app on my phone or website on my computer much since most of what I need is automated.