Tracking Netflix and Amazon Prime Usage

Recently, I was wondering how much my family actually uses Netflix and Amazon Prime video, both of which we pay monthly subscriptions. I searched this community and Reddit but didn’t find any ideas as to how I could track (ideally hours/day or hours/week) each service is actually used. I have Home Assistant, of course, and also have Pi-hole. I would be willing to put another piece of (free) software on a RPi if such software exists that would meet this need. I mainly use Amazon Fire Sticks to play both Netflix and Prime (on 2 TVs).

So, does anyone have any ideas or solutions on how to accomplish this?

Don’t they display what app is used?

Chromecast displays it like this:

If I use Netflix then it displays Netflix at that position.

Set up a template to display this as the state and then use history stats sensor on that sensor to get the usage.

1 Like

Thanks for the idea! I’m not sure where to look for that info; I don’t see it on my Chromecast entity or device anywhere, nor do I seem to have FireTV devices except through my Google Wifi and Alexa Media Player. Nor do I find an (native) integration for Fire TV. Am I not looking in the right places?

This was in developer tools on the media_player entity, the attributes.

1 Like

Thank you! I see a lot more of the info there, but still not all of it. I’ll dig in deeper when I have a minute to see if I can find the relevant info and apply your template idea.

It will only show this information when it is actively streaming something, if the Chromecast is off or Idle it won’t have any of the additional attributes.

1 Like

I have been working on something similar for a while. I have got it to the point of tracking the usage for the streaming services on each of the entities in Home Assistant. This is the automation I have going at this point.

alias: Track Streaming Service Usage
description: ''
trigger:
  - platform: state
    entity_id: media_player.family_room_xbox
    attribute: media_title
  - platform: state
    entity_id: media_player.xbox_one_x_2
    attribute: media_title
  - platform: state
    entity_id: media_player.family_room_tv
    attribute: source
condition: []
action:
  - service: input_text.set_value
    data:
      value: >-
        {{ trigger.from_state.attributes.source }}{{
        trigger.from_state.attributes.media_title }}
    target:
      entity_id: input_text.temp_daily_usage_source_tracker
  - service: input_text.set_value
    data:
      value: '{{ trigger.entity_id }}'
    target:
      entity_id: input_text.temp_daily_usage_entity_tracker
  - choose:
      - conditions:
          - condition: state
            entity_id: input_text.temp_daily_usage_entity_tracker
            state: media_player.family_room_tv
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Hulu") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_tv_source_change_time')))
                        / 60) | int %} {{ states('input_number.daily_hulu_use')
                        | int + elapsed_time }}
                    target:
                      entity_id: input_number.daily_hulu_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "YouTube") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_tv_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_youtube_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_youtube_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Amazon Prime Video") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_tv_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_amazon_prime_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_amazon_prime_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Netflix") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_tv_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_netflix_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_netflix_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Disney+") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_tv_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_disney_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_disney_use
            default: []
          - service: input_datetime.set_datetime
            data:
              timestamp: '{{ now().timestamp() }}'
            target:
              entity_id: input_datetime.family_room_tv_source_change_time
      - conditions:
          - condition: state
            entity_id: input_text.temp_daily_usage_entity_tracker
            state: media_player.xbox_one_x_2
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Hulu") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.xbox_one_x_source_change_time')))
                        / 60) | int %} {{ states('input_number.daily_hulu_use')
                        | int + elapsed_time }}
                    target:
                      entity_id: input_number.daily_hulu_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "YouTube") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.xbox_one_x_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_youtube_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_youtube_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Prime Video US (Xbox)") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.xbox_one_x_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_amazon_prime_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_amazon_prime_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Netflix") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.xbox_one_x_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_netflix_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_netflix_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Disney+") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.xbox_one_x_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_disney_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_disney_use
            default: []
          - service: input_datetime.set_datetime
            data:
              timestamp: '{{ now().timestamp() }}'
            target:
              entity_id: input_datetime.xbox_one_x_source_change_time
      - conditions:
          - condition: state
            entity_id: input_text.temp_daily_usage_entity_tracker
            state: media_player.family_room_xbox
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Hulu") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_xbox_source_change_time')))
                        / 60) | int %} {{ states('input_number.daily_hulu_use')
                        | int + elapsed_time }}
                    target:
                      entity_id: input_number.daily_hulu_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "YouTube") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_xbox_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_youtube_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_youtube_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Prime Video US (Xbox)") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_xbox_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_amazon_prime_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_amazon_prime_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Netflix") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_xbox_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_netflix_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_netflix_use
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ is_state("input_text.temp_daily_usage_source_tracker",
                      "Disney+") }}
                sequence:
                  - service: input_number.set_value
                    data:
                      value: >-
                        {% set elapsed_time = ((as_timestamp(now()) -
                        as_timestamp(states('input_datetime.family_room_xbox_source_change_time')))
                        / 60) | int %} {{
                        states('input_number.daily_disney_use') | int +
                        elapsed_time }}
                    target:
                      entity_id: input_number.daily_disney_use
            default: []
          - service: input_datetime.set_datetime
            data:
              timestamp: '{{ now().timestamp() }}'
            target:
              entity_id: input_datetime.family_room_xbox_source_change_time
    default: []
mode: queued

There are a couple of input helpers that are used in this automation.

  • A numeric helper for each of the services that track the usage. Each of these are reset to 0 every night.
  • A text input helper for the entity that triggered the automation.
  • A text input helper to track which service was just closed or exited from.
  • A date time input helper for each entity being watched to track when the last state change happened.

With all of this, I now can track how long each of the streaming services are being used across my devices.

I am now trying to figure out how to report on this information. I’d like to be able to see how long each service was used per day for a month… Or something like that.

2 Likes

It looks like you created a history stats equivalent using complex automations.

Could you share how your helpers look like? Trying to adapt your automation to my devices but nothing happens