Is it possible after 2 hours of not using an android app, turn off a smart plug?

Tags: #<Tag:0x00007fc3f60681e8> #<Tag:0x00007fc3f60680f8> #<Tag:0x00007fc3f6068030>

Hello,
I’m trying to figure out if it is possible to do an automation …
I own 4 GoogleTV
and 1 pc with steam.
and 1 smart plug.

The pc is set to turn on automatically when plug turn on.

I managed to set that when I turn on steam link on googletv, the smart socket turns on and the pc starts up and I play …

now i would like to know if it is possible if none of the googletv uses steam link, after 2 hours I turn off the smart plug

the pc is already set up that if it has no requests it turns off after 1 hour and 30 minutes.

Now I just have to figure out how to turn off the smart plug.

It’s possible?

Thank you


EDIT:

I think a code like this, but i cannot pur a AND in trigger…

# STEAM
- alias: Steam OFF
  trigger:  
  - platform: template
    value_template: "{{ state_attr('media_player.android_castsoggiorno', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_castcucina', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
    platform: state
  - platform: template
    value_template: "{{ state_attr('media_player.android_caststudio', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_castcameretta', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_casttaverna', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  condition:
   - condition: state
      entity_id: switch.steam_mss310_main_channel
      state: on
  action:
   - service: switch.turn_off
     entity_id: switch.steam_mss310_main_channel

If the computer turns off anyways why do you need to turn of the switch?

Is it to boot it up?
Can’t you use WOL?

Thanks for the reply,
I have set in the bios that when ac restored the pc turns on.

i can’t use wol because google tv wouldn’t … so i thought this trick

Soo I use a plug to turn on my pc like you, what you can do is check what state the google tv has when its idle. and just validate if the state is the same for 2 hours, turn off the plug.

Thanks
But how check 4 different google tv are in idle and not in steam state for 2 hours?

Try with an up?

I am looking for: an automation that checks the status of 4 google tv and if all 4 have not used the steam app for at least 2 hours, turn off a smart plug, please help

What happens with your current automation?
I think it switches of when any of them has not been used for two hours, right?

If so then you need to add all that you have as trigger also as condition.

Either with this code:

- alias: Steam OFF
  trigger:  
  - platform: template
    value_template: "{{ state_attr('media_player.android_castsoggiorno', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_castcucina', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_caststudio', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_castcameretta', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_casttaverna', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: switch.steamos_mss310_main_channel
      state: 'on'
    - condition: or
      conditions:
        - condition: template
          value_template: "{{ state_attr('media_player.android_castsoggiorno', 'app_name') != [ 'Steam' ] }}"
        - condition: template
          value_template: "{{ state_attr('media_player.android_castcucina', 'app_name') != [ 'Steam' ] }}"
        - condition: template
          value_template: "{{ state_attr('media_player.android_caststudio', 'app_name') != [ 'Steam' ] }}"
        - condition: template
          value_template: "{{ state_attr('media_player.android_castcameretta', 'app_name') != [ 'Steam' ] }}"
        - condition: template
          value_template: "{{ state_attr('media_player.android_casttaverna', 'app_name') != [ 'Steam' ] }}"
  action:
  - service: switch.turn_off
    entity_id: switch.steamos_mss310_main_channel

or with this:

- alias: Steam OFF
  trigger:  
  - platform: template
    value_template: "{{ state_attr('media_player.android_castsoggiorno', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_castcucina', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_caststudio', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_castcameretta', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ state_attr('media_player.android_casttaverna', 'app_name') != [ 'Steam' ] }}"
    for:
      hours: 2
  condition:
    - condition: state
      entity_id: switch.steamos_mss310_main_channel
      state: "on"
  action:
  - service: switch.turn_off
    entity_id: switch.steamos_mss310_main_channel

Automation never starts

solved with this code (it was enough to put a not before state_...)

- alias: SteamOS OFF
  trigger:  
  - platform: template
    value_template: "{{ not state_attr('media_player.android_castsoggiorno', 'app_name') in [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ not state_attr('media_player.android_castcucina', 'app_name') in [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ not state_attr('media_player.android_caststudio', 'app_name') in [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ not state_attr('media_player.android_castcameretta', 'app_name') in [ 'Steam' ] }}"
    for:
      hours: 2
  - platform: template
    value_template: "{{ not state_attr('media_player.android_casttaverna', 'app_name') in [ 'Steam' ] }}"
    for:
      hours: 2
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: switch.steamos_mss310_main_channel
      state: 'on'
    - condition: state
      entity_id: switch.workbook_mss310r_main_channel
      state: 'off'
    - condition: or
      conditions:
        - condition: template
          value_template: "{{ not state_attr('media_player.android_castsoggiorno', 'app_name') in [ 'Steam' ] }}"
        - condition: template
          value_template: "{{ not state_attr('media_player.android_castcucina', 'app_name') in [ 'Steam' ] }}"
        - condition: template
          value_template: "{{ not state_attr('media_player.android_caststudio', 'app_name') in [ 'Steam' ] }}"
        - condition: template
          value_template: "{{ not state_attr('media_player.android_castcameretta', 'app_name') in [ 'Steam' ] }}"
        - condition: template
          value_template: "{{ not state_attr('media_player.android_casttaverna', 'app_name') in [ 'Steam' ] }}"
  action:
  - delay: 00:01:30
  - service: switch.turn_off
    entity_id: switch.steamos_mss310_main_channel

the only problem now is if I have

entity_id: switch.workbook_mss310r_main_channel

When switched on for more than two hours from the start of the automation, it doesn’t start.
is there a code to repeat the automation every two hours?

thank you

This seems a bit over-complicated. If the PC already turns off after 1 hr 30 min, why not ping it every 15 min to see whether it is online, and if not turn off the plug?

the pc does not turn off after 1h30 but turns off when it is not used for more than 1 hour. the googletv use the pc, i would like the google tvs do not use the pc (ie they do not use the steam app) for more than two hours turn off the plug. I need the workbook plug because if I’m using another pc for checks, updates, etc., steamos should not be turned off … so ultimately: I wanted to do this:

  • the google tvs don’t use the steam app for more than two hours

  • the workbook plug is off

  • then turn off the streamos plug.

  • if the workbook plug is on

  • or any google tv has used the steam app for less than two hours,

  • do not switch off the steamos plug.