🔛 Switch - Turn ON & OFF Entities

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

GitHub Click Here

Like this blueprint? Consider hitting the :heart: button below :+1:

Version: 1.3 :fire:

Need help? :eyes: See our FAQ: Click Here

:newspaper: The Automation Process

  • When you turn any switch ON it will turn ON the main entity input.
  • When you turn all the switches OFF it will turn OFF the main entity input.
  • You have the option to input an alternating entity that will be the opposite state to the main entity.

NOTE - The switch can be any entity with an ON & OFF state.

:rocket: CHANGELOG

Version: 1.3 - 2 Dec-23 You can now add multiple switches.
Version: 1.2 - 1 Nov-23 major code update.
Version: 1.1 - 30 Oct-22 initial release

:shield: MY OTHER BLUEPRINTS

:bulb: Sensor Light - Motion Sensor - Door Sensor - Sun Elevation - LUX Value - Scenes - Time
:high_brightness: Smart Light - Entity - Sun Elevation - Ambient & Time Triggers
:infinity: Sensor Light Add On - Media & Movie Lights - House Alarm Lights - Smoke Alarm Lights & Exhaust Fans + More
:shower: Bathroom Humidity Exhaust Fan
:low_battery: Low Battery Notifications & Actions
:vibration_mode: Appliance Notifications & Actions - Washing Machine - Clothes Dryer - Dish Washer - ETC
:loudspeaker: Notifications & Announcements
:calendar: Calendar Notifications & Actions
:round_pushpin: State Notifications & Actions
:robot: Android Notification Channel Manager
:toilet: Toilet Exhaust Fan with time delay
:hourglass_flowing_sand: Entity - Run ON Timer
:stopwatch: Trigger - Run ON Timer
:magic_wand: Manual light control with auto OFF
:door: Closet, Pantry, and Cupboard Lighting
:timer_clock: Timer
:thermometer: Temperature Control Fan
:snowflake: Temperature Control Exhaust Fan - Inverted
:eight_spoked_asterisk: Toggle Switch - Turn ON & OFF Entities
:nazar_amulet: Press Button - Turn ON & OFF Entities

Like this blueprint? Consider hitting the :heart: button below :+1:

4 Likes

FAQ

Q: What type of switch can I use?

A: The switch must have a state that goes ON when you switch / press it, and then when you switch / press it again the state goes OFF. If you have a push button that goes ON/OFF in one press and when you press it again it will go ON/OFF then I have a different Blueprint called Push Button Relay - Contactor. It works the same as this blueprint but the trigger is different.

Q: Can I put the same entity into the normally open & normally closed fields?

A: No, you must only choose one field, normally open or normally closed per entity.

How can this handle dual input switches?
Switch 1: Shelly running in detached mode, this works fine by itself
Switch 2: EP1 showing presence as (Detected/Clear)

not sure what you are asking. Maybe explain what you are trying to do.

I have a light group that is controlled from HA.

Then I have 2 separate inputs that I would like to control them from.
The first is a wall switch that is exposed to HA, with ON/OFF.
The second is mmWave presence, this reports Detected/Clear.

At the moment I have your blueprint working only with the switch, but without the mmWave.

Using the blueprint without adding lots of extra logic would be great as I will need to replicate it for each room.

Have you seen my :bulb: Sensor Light blueprint?

In the sensor light blueprint, your MMWave would be the trigger and your wall switch would be the by-pass. For by-pass selection you would select “Enable the By-pass - Turn lights ON”. Then you would just add all your lights in as entities.

Let me know it this works for you

Oh wow, that looks perfect.

The only other one I noticed was the push button. Thank you very much

no problem, you will have a lot of options now and there is a bigger plan on the road map ahead.

New update 1.2

:warning: Breaking Change :broken_heart:

New Feature :new:

Code Update - This is a major code and blueprint update. It will break your existing blueprint. Hopefully this is a lot cleaner & will survive a HA restart. Sorry it had to be done.

If you like this blueprint? Consider hitting the :heart: button in the top post :+1:

If you like my blueprints, and would like to show your support or just say thank you? Click Here :smiling_face_with_three_hearts:

Enjoy

Blacky :grinning:

New update 1.3

:warning: Some work is required in this upgrade. Please see below on the steps when upgrading. It is easy and not a breaking change.

New Feature :new:

Switch - You can add as many switches as you like. If any switch is ON it will turn ON the main entity. All switches must be OFF to turn OFF the main entity.

Why multiple switches? I use this to control my WLED lights transformer. WLED has a feature for adding in a relay but you have to wire it all up etc. What I do is add all my lights (In WLED it is call segments) into the switch. In the main entity I add my smart plug (plug my transformer into smart plug) and the main switch for WLED. The transformer feeds the LED’s not the ESP32 and I have another cable (USB C) supplying the ESP32 so everything is available in HA 24/7. Now when any light is turned ON, it turns on the main entities that are my smart plug (transformer) and WLED main switch and the lights turn ON. When all the light are turned OFF the transformer and WLED main switch is turned OFF.

Why do this? Because even though the LED lights are turned OFF they still draw power. This way they only draw power when they are turned ON :wink:

You can do other things with it but this is one example.

:warning: :stethoscope: STEPS REQUIRED WHEN UPGRADING :white_check_mark:

1 - Upgrade your blueprint.
2 - Go into your automation (the ones using this blueprint). You will see the switch has a missing input.

3 - Click the 3 dots top right and “Edit in YAML”.

2

4 - We are looking for the words or input called “switch: ???

3

  1. Delete this line,(“switch: ???”)

4

6 - Then click 3 dots and select “Edit in visual editor”

5

  1. Enter in your switch again.

8 - Click save, and you’re done.

If you like this blueprint? Consider hitting the :heart: button in the top post :+1:

If you like my blueprints, and would like to show your support or just say thank you? Click Here :smiling_face_with_three_hearts:

Enjoy

Blacky :grinning:

The version 1 code works well, but when the power is cut off and back on again, the code does not work. What is the solution?

@Athe.Coding

Welcome to the community.

Not sure what you are referring to. We use this to turn on our transformers for our LED lighting so power is not used when the LED lights are OFF and it works. Maybe if you can give us some more information so we can look at it.

Blacky :smiley:

I found a solution to my problem. I modified the code that you posted. The idea is that when the first switch is working, the second switch should be turned off, and when the electricity goes out and then comes back on, the second switch should turn off automatically after a short period because the first switch in on .

blueprint:
  name: Switch - Turn ON & OFF Entities
  description: "# \U0001F51B Switch - Turn ON & OFF Entities\n**Version: 1.3**\n\nLet us know what you think of this blueprint and for community support including updates: [Click Here](https://community.home-assistant.io/t/switch-turn-on-off-entities/481546)\n\n**The Automation Process:**\n  - When you turn any switch ON it will turn ON the main entity input.\n  - When you turn all the switches OFF it will turn OFF the main entity input.\n  - You have the option to input an alternating entity that will be the opposite state to the main entity when the switch is ON.\n\n**NOTE** - The switch can be any entity with an ON & OFF state.\n\nRequired = *\n\nNeed help? See our FAQ: [Click Here](https://community.home-assistant.io/t/switch-turn-on-off-entities/481546/2?u=blacky)\n\n**If you like my blueprints, and would like to show your support or just say thank you?** [Click Here](https://www.paypal.com/donate/?hosted_button_id=WAZS3QSDTPGA8) \U0001F642\n"
  domain: automation
  input:
    switch:
      name: Switch *
      description: The switch that controls the entities.
      selector:
        entity:
          multiple: true
    main_entity:
      name: Main Entity *
      description: The main entity that will be turned ON when the switch is ON.
      selector:
        entity:
          multiple: true
    alternating_entity:
      name: Alternating Entity (optional)
      description: The alternating entity that will be the opposite state to the main entity when the switch is ON.
      default: []
      selector:
        entity:
          multiple: true
  source_url: https://gist.github.com/Blackshome/dbcd8ebfdd0350144fc1503fc0fa8112
variables:
  switch: !input switch
  main_entity: !input main_entity
  alternating_entity: !input alternating_entity
trigger:
  - platform: homeassistant
    event: start

  - platform: state
    entity_id: !input switch
    from: 'off'
    to: 'on'

  - platform: state
    entity_id: !input switch
    from: 'on'
    to: 'off'
    for:
      milliseconds: 200

  - platform: state
    entity_id: !input main_entity
    from: 'off'
    to: 'on'

  - platform: state
    entity_id: !input main_entity
    from: 'on'
    to: 'off'
    for:
      milliseconds: 200

action:
  - choose:
    - alias: Check if any alternating entity is entered
      conditions:
        - '{{ alternating_entity == [] }}'
      sequence:
        - choose:
          - alias: Check if switch is on
            conditions:
              - condition: state
                entity_id: !input switch
                state: 'on'
                match: any
            sequence:
              - alias: Turn OFF the main entities
                service: homeassistant.turn_off
                target:
                  entity_id: !input main_entity
    default:
      - choose:
        - alias: Check if switch is on
          conditions:
            - condition: state
              entity_id: !input switch
              state: 'on'
              match: any
          sequence:
            - alias: Turn OFF the main entities
              service: homeassistant.turn_off
              target:
                entity_id: !input main_entity
            - alias: Turn OFF the alternating entity entities
              service: homeassistant.turn_off
              target:
                entity_id: !input alternating_entity
        

Hey Blacky,
thanks for the blueprint! I have a feature request. Not sure which of your template fits best, but my request is that turning on and off should be limited to a specific number of times per hour.

I have a recirculator that should be started a couple of times per hour and I was wondering how to achieve that using your templates. I believe it’s a good use case for this one, so before I started writing something on my own, I wondered if you are interested in adding it as a feature.

Here’s the manual information that should make better sense than me:

  • Switch-on/off procedures via mains voltage ≤ 100/24 h.
  • ≤ 20/h for a switching frequency of 1 minute between switching on/off via mains voltage.

@giannoug

Hi George, welcome to the community.

This seams like a unique use case. I not really understanding what you are doing but I understand that you would like to to turn ON and OFF a couple times per hour. If this is just on a time base then you could create a schedule helper and set the times you would like it ON and OFF throughout the day. Then use that schedule helper in the Switch to turn ON / OFF what you would like.

To create a schedule helper go to settings > device & services > helpers tab at top > create helper button > schedule then set the times you would like.

Hope this helps you.

Blacky :smiley:

Not exactly, I would like to limit how many times the device could be turned on and off in a specific period

You would have to do a custom automation for this then.

Blacky :smiley: