Kodi TV Kids Police

Does anyone think this could be done? Could I time how much TV has been watched, seeing as Kodi sends playing updates to HA? Can I then send a STOP command back somehow?

You can create a history stats sensor to time how long the TV has been on today and trigger off that:

And yes all media players have a stop service.

Great that looks a good start. Does Kodi send anything about what its playing? Music/TV/Film? Genre and so on?

These are the attributes of my currently playing movie:

volume_level: 1
is_volume_muted: false
media_content_id: 
imdb: tt20859464
tmdb: '983282'

media_content_type: movie  ### <--- This what you are after?
media_duration: 5599
media_position: 1849
media_position_updated_at: 2024-02-19T09:01:52.668038+00:00
media_title: The Artifice Girl
media_album_name: 
media_series_title: 
media_season: -1
media_episode: -1
entity_picture: /api/media_player_proxy/media_player.lounge_osmc_kodi?token=950909c497300feea2a78fc5e64166e02cd5a5330c352159b65f6f81e684d0f0&cache=58fef35fba0b74df
friendly_name: Lounge Kodi
supported_features: 186303
icon: mdi:kodi

That looks good, just a shame it doesn’t send the genre of the TV that’s being watched, otherwise it would block me watching too much TV as well haha. Need to filter for “kids” somehow. I suppose it’d be an imdb lookup then?

This seems to work, in that it gives you how many hours of TV have been watched.

sensor:
  - platform: history_stats
    name: TV ON today
    entity_id: media_player.server
    state: "playing"
    type: time
    start: "{{ today_at() }}"
    end: "{{ now() }}"

Stops anyone not just the kids watching too much telly.

alias: Too Much TV
description: ""
trigger:
  - platform: device
    device_id: blahblah
    domain: media_player
    entity_id: blahblah
    type: playing
condition:
  - condition: numeric_state
    entity_id: sensor.tv_on_today
    above: 2
action:
  - service: media_player.media_stop
    metadata: {}
    data: {}
    target:
      device_id: d42592247da5ffa33e1efd46414c0d2b
mode: single