Time Limits

Good Day All,

My kids have just started getting in to playing on the xbox. They are still young so I dont want them getting hooked,. and therefore want to limit the time they use it per day. The microsoft / xbox family safe is limited in its features but could be an option. The issue is, they will just go on the TV once the Xbox time is up.

So my plan is to have the TV and Xbox, connected to a smart plug. Then I will time limit the smart plug so everything turns off once the time limit is reached.
The time limit can be spread across the whole day. So if its a 40min daily limit, they might want 10 mins in the morning, and 30 mins in the evening, etc.

I was wondering if I could get some guidance on the best methods to achieve this. Will I need to set up Binary sensors etc?

Thanks in advance
Russ

Hi,

There are many ways to achieve what you want. A very simple approach consists of a combination of a sensor that counts the time and resets once a day and a simple automation.

You add the sensor template in the configuration.yaml.

template:
  - trigger:
      - platform: time_pattern
        seconds: "/60"
    sensor:
      - name: "xbox_runtime_today"
        unit_of_measurement: "min"
        state: >
          {% set last = this.state() | float(0) %}
          {% set power = state('sensor.tapo_p110m_power') | float(0) %}  # REPLACE BY YOUR PLUG NAME
          {% if power > 20 %}  # SET W THRESHOLD
            {{ (last + 1) | round(1) }}
          {% else %}
            {{ last }}
          {% endif %}

automation:
  - alias: "Xbox Access Control"
    trigger:
      - id: reset
        platform: time
        at: "03:00:00"   # RESETS AT 3 AM

      - id: limit
        platform: numeric_state
        entity_id: sensor.xbox_runtime_today
        above: 120   # MAX TIME PER DAY

    action:
      - choose:
          - conditions:
              - condition: trigger
                id: reset
            sequence:
              - service: homeassistant.reload_config_entry
                target:
                  entity_id: sensor.xbox_runtime_today

          - conditions:
              - condition: trigger
                id: limit
            sequence:
              - service: switch.turn_off
                target:
                  entity_id: switch.xbox    # REPLACE WITH YOUR PLUG DEVICE

But I trust that the HA Pros will come uo with something shorter :slight_smile:

arrrggg man, thanks so much for writing all that code out for me. Really appreciate it.
I’ll give that a go

I’ve typically done must of my setup (binary sensors, etc) using the GUI, I’ve not really experimented the configuration.yaml yet. Is it easy to do? Do I need to place the code in a specific location?

I used the GUI myself to draft the code, simply replaced my sensor names by generic ones. It’s not very elegant and there are certainly better and more efficient ways.

It’s like editing any text file. You will need an editor though. I recommend Blueprint Studio (installed through HACS).

The code goes anywhere in the file, just watch indentation (2 spaces) and that there is only one template: in case you already have similar content. In the long run you may move such definitions out of configuration and place them in own files in subdirectories which you add with !include commands. You will those in the file.

Just killing the power on an Xbox with a hard drive may not be ideal.

Good point.

Now things start getting more complicated. The OP would need to look for a Xbox integration and send it to sleep before shutting off power. However, Microsoft allows to set use times per account. See Xbox Family Settings-App (German site). That would leave just TV.

Now kids are creative. They will probably quickly discover that the smart plug has s button to switch it on. :smile:

Arrrr, very good point about the HDD.

I have thr xbox integrated in to HS, amd there is a entity for its power as below.

Could a sensor be linked to this to calculate the amount of time it been in its “on” state. The turn it off via that entity?

The smart plug will be well tucked away and hidden for them to get even close to mwhahahaha

I’d tell the kids that you will get notified if they go over time. And instead of turning off the power turn on an alarm bell…

You’ve not met my kids!! :man_facepalming::man_facepalming::joy::joy:

just use Microsoft family/family safe. You can control the contents/time etc… I used that for years.

Right, as already suggested: :wink:

Yes, not a big deal to set up a helper that counts uptime of the entity. But check the device page. What other entities does it expose?