Excessive Data Usage & Battery Drain

May be I have a partial solution but I need some help to a complete solution. As I explain, I have battery drain and huge data traffic (that explain the battery drain). I have few dashboards and in the second one I have a page with all my webcams. As I view it, of course, I have a lot of traffic. But closing the app (installed on a samsung a51 - android) or send it to the background won’t stop the traffic. Only moving to another dashboard and closing it seems to work and that’s isn’t a good solution.
First thing I do is to detect the traffic usage so I create a helper (settings-devices-helper). The logical thing to use is an Utility Meter but didn’t work for me even if I set Net consumption. The thing that work is Derivative sensor : name: Phone HA A51 Traffic; input sensor: App Rx Gb (from Mobile App integration); id: sensor.phone_a51_rx_p6_00000_mn_tus; precision 6; time window: 0:00:00; metric: none; time unit: seconds. It works.
Now I have to find a way to stop the streams when I don’t need to view them. So I made an automation and I use Browser Mod.

alias: Phone A51 Protect Data Trafic
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.phone_a51_rx_p6_00000_mn_tus
    above: 0.001
condition:
  - not:
      - condition: state
        entity_id: binary_sensor.sm_a515f_interactive
        state: "on"
action:
  - service: browser_mod.navigate
    target:
      device_id: 7722e5d54be759d6166687aaad5e299c
    data:
      path: /dashboard-giardino
mode: single

What I want to do in this automation is:

  1. When the data traffic is high
  2. And the app is not active (closed/background)
  3. Resolve the traffic in some manner:
    3.1 Move to another page using browser mode (do not resolve: it move to a new page when it come from background)
    3.2 Restart service and integration like go2rtc, Android Ip Webcam, Tapo, Imou … (do not resolve: a bad solution with tapo integration stop responding)
    3.3 Restart Home Assistant (a bit extreme solution)
    3.4 Service media_player.stop (device target. android browser id ) do nothing.
    3.5 ???

Any idea for point 3.5 ???

only 1 fix, do not exit the app with a camera in view. MOve them to a different dashboard/view and leave the app on a view that does not contain anything streaming. thats all you need to do. Dont keep a camera open or in view when leaving.

Yes, that will stop the traffic but is not a solution for me. I need something to automatically stop the traffic when I don’t view my page with streams. Something like what I described in 3.1 point.

I think it works now.
First, in automation the trigger was its traffic and the condition to proceed is that I don’t view the page with streams.
I reverse it: now the trigger is that i don’t view anymore the streams and if the traffic is high then do …
I add a helper: input_datetime.phone_ha_a51_traffic_last_trigger to see the last time then this automation has run.

alias: Phone A51 Protect Data Trafic
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.phone_a51_rx_p6_00000_mn_tus
    above: 0.0005
    enabled: false
  - platform: state
    entity_id:
      - sensor.browser_a51_browser_visibility
    from: null
    to: hidden
  - platform: state
    entity_id:
      - sensor.browser_a51_browser_visibility
    from: null
    to: unavailable
  - platform: state
    entity_id:
      - sensor.browser_a51_browser_visibility
    from: null
    to: unknown
condition:
  - condition: numeric_state
    entity_id: sensor.phone_a51_rx_p6_00000_mn_tus
    above: 0.0005
action:
  - service: input_datetime.set_datetime
    target:
      entity_id: input_datetime.phone_ha_a51_traffic_last_trigger
    data:
      datetime: "{{ now() }}"
  - service: browser_mod.navigate
    target:
      device_id: 7722e5d54be759d6166687aaad5e299c
    data:
      path: /dashboard-giardino
  - service: notify.mobile_app_sm_a515f
    metadata: {}
    data:
      message: Traffico ridotto in automatico.
mode: single