Disable and enable wlan on time and day

Hi,

for know I have two automations for enable and one for disable.

 - id: '1641724966000'
   alias: Gast Wlan einschalten
   description: Gast Wlan einschalten
   trigger:
   - platform: time
     at: 07:45
   condition:
   - condition: time
     after: 07:30
     before: '15:00'
     weekday:
     - fri
   action:
   - service: switch.turn_on
     target:
       entity_id: switch.fritz_box_7590_wi_fi_gast_tux
   mode: single

How can I manage this with one automation? I think best way would be set this entity to off for default and only on when time and day fits. But were to set this to off?

Thanks Micha

Please format your yaml properly – see point 11 in the guidelines.

You can combine the automations using trigger IDs:

alias: Gast Wlan
description: ''
mode: single
trigger:
  - platform: time
    at: '07:45'
    id: 'on'
  - platform: time
    at: '21:00'
    id: 'off'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'on'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.fritz_box_7590_wi_fi_gast_tux
      - conditions:
          - condition: trigger
            id: 'off'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.fritz_box_7590_wi_fi_gast_tux
    default: []

Curious, if you want to disable whole wifi or disable it for a given device? There should be individual switches to enable/disable their connection.

I use the guest wlan only on friday for my home office pc. Which has a extra wlan to not let it in my network.

Sadly it doesn’t work as expected. This it how it looks like.


- id: '1641724966000'
  alias: Gast Wlan einschalten
  description: Gast Wlan einschalten
  trigger:
  - platform: time
    at: 07:45
    id: 'on'
  - platform: time
    at: '15:00'
    id: 'off'
  condition: []
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: 'on'
      - condition: time
        weekday:
        - fri
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.fritz_box_7590_wi_fi_gast_tux
      - choose:
        - conditions:
          - condition: trigger
            id: 'off'
          sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.fritz_box_7590_wi_fi_gast_tux
        default: []
    default: []

I try to understand the automation debugging. This show me:



Executed: 23. Januar 2022, 10:59:06
Result:

choice: default
choose:
  - conditions:
      - condition: trigger
        id: 'on'
      - condition: time
        weekday:
          - fri
    sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.fritz_box_7590_wi_fi_gast_tux
      - choose:
          - conditions:
              - condition: trigger
                id: 'off'
            sequence:
              - service: switch.turn_off
                target:
                  entity_id: switch.fritz_box_7590_wi_fi_gast_tux
        default: []
default: []

I think i have misunderstood something. The goal is, that the wlan is only on on Friday between 07:45 - 15:00 O’clock.
I understand it there for, that the default action should be set, if the time range not match. And the automation is set to default in the debug mode. So it should be triggered or?

You seem to have two choose nested, so your trigger id off condition will never be satisfied.

You need a single choose with multiple conditions / sequence blocks.

- id: '1641724966000'
  alias: Gast Wlan einschalten
  description: Gast Wlan einschalten
  trigger:
  - platform: time
    at: 07:45
    id: 'on'
  - platform: time
    at: '15:00'
    id: 'off'
  condition: []
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: 'on'
      - condition: time
        weekday:
        - fri
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.fritz_box_7590_wi_fi_gast_tux
    - conditions:
      - condition: trigger
        id: 'off'
      sequence:
      - service: switch.turn_off
        target:
          entity_id: switch.fritz_box_7590_wi_fi_gast_tux
    default: []
- id: '1641724966000'
  alias: Gast Wlan einschalten
  description: Gast Wlan einschalten
  trigger:
    - id: 'on'
      platform: time
      at: '07:45'
    - id: 'off'
      platform: time
      at: '15:00'
  condition: '{{ now().isoweekday() == 5 }}'
  action:
    - service: 'switch.turn_{{ trigger.id }}'
      target:
        entity_id: switch.fritz_box_7590_wi_fi_gast_tux

thanks both of you for the input. The first I managed to implement after I found and used the right action (auswählen). Sometimes it is hard to replicate this trough the UI.

@123
Also a nice idea, but I don’t get it to work. I assume I have to use the yaml mode, but there are always an error so that I can save this.

Edit: I found it, have to choose template to insert the weekday.

What’s the error?

Because it might simply be due to how you are copy-pasting the example into the Automation Editor.

It is accepted without errors as seen here:

yeah, pasting works and I found the template in the UI where it is also to paste.
Tanks

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. It will also place a link below your first post that leads to the solution post. All of this helps users find answers to similar questions. For more information refer to guideline 21 in the FAQ.

yeah, I will set the solution while I know it is really working. I try to test it and set the time trough the developer tools, but without success.
If you have a tip for me, how I can test it , I’d love to

You can test it by simply changing the two scheduled times to a few minutes from now and replace the 5 in the condition to 7 (which represents today, Sunday). After you have confirmed it works, undo the modifications.

both solutions works well.