Skip to content

Instantly share code, notes, and snippets.

@Resinchem
Last active April 28, 2024 14:26
Show Gist options
  • Save Resinchem/e0daa78f2f3bbb2db6a393f3f3b22e56 to your computer and use it in GitHub Desktop.
Save Resinchem/e0daa78f2f3bbb2db6a393f3f3b22e56 to your computer and use it in GitHub Desktop.
Example Home Assistant Virtual Switch Examples as shown in YouTube Video
# ==========================================================
# DASHBOARD YAML
# All examples will need to be edited to use your entity
# names and particular installation.
#
# This dashboard example includes a toggle with conditional
# cards to switch between custom button card and standard
# entities display as shown in the video:
# https://youtu.be/mj2CIKqrQlc
# ==========================================================
- title: Stage
path: stage
badges: []
cards:
- type: vertical-stack
cards:
- text: Physical Light Switch
type: custom:text-divider-row
- card:
type: entities
entities:
- entity: light.basement
name: Basement Main Lights
icon: mdi:lightbulb-group
conditions:
- entity: input_boolean.show_standard_cards
state: 'on'
type: conditional
- card:
square: false
type: grid
columns: 3
cards:
- aspect_ratio: 1.5/1
color: rgb(0,255,0)
color_type: card
entity: light.basement
show_name: false
show_state: true
state:
- color: rgb(200,0,0)
icon: mdi:lightbulb-off
value: 'off'
type: custom:button-card
conditions:
- entity: input_boolean.show_standard_cards
state: 'off'
type: conditional
- text: Virtual (template) Switches
type: custom:text-divider-row
- card:
type: entities
entities:
- entity: switch.sw_basement_100
name: 100%
icon: mdi:circle-slice-8
- entity: switch.sw_basement_75
name: 75%
icon: mdi:circle-slice-6
- entity: switch.sw_basement_50
name: 50%
icon: mdi:circle-slice-4
- entity: switch.sw_basement_25
name: 25%
icon: mdi:circle-slice-2
conditions:
- entity: input_boolean.show_standard_cards
state: 'on'
type: conditional
- card:
type: grid
square: false
columns: 4
cards:
- aspect_ratio: 1.2/1
color_type: card
entity: switch.sw_basement_100
icon: mdi:circle-slice-8
name: 100%
state:
- color: rgb(0,128,0)
value: 'on'
type: custom:button-card
- aspect_ratio: 1.2/1
color_type: card
entity: switch.sw_basement_75
icon: mdi:circle-slice-6
name: 75%
state:
- color: rgb(0,128,0)
value: 'on'
type: custom:button-card
- aspect_ratio: 1.2/1
color_type: card
entity: switch.sw_basement_50
icon: mdi:circle-slice-4
name: 50%
state:
- color: rgb(0,128,0)
value: 'on'
type: custom:button-card
- aspect_ratio: 1.2/1
color: rgb(0,255,0)
color_type: card
entity: switch.sw_basement_25
icon: mdi:circle-slice-2
name: 25%
state:
- color: rgb(0,128,0)
value: 'on'
type: custom:button-card
conditions:
- entity: input_boolean.show_standard_cards
state: 'off'
type: conditional
- text: ' '
type: custom:text-divider-row
- type: entities
entities:
- entity: input_boolean.show_standard_cards
- entity: script.virtual_switch_trigger_booleans
name: Trigger Trash and Recyclables
- type: vertical-stack
cards:
- text: Physical TV Switch
type: custom:text-divider-row
- card:
type: entities
entities:
- entity: switch.roku
name: Main TV
icon: mdi:gamepad-outline
conditions:
- entity: input_boolean.show_standard_cards
state: 'on'
type: conditional
- card:
square: false
type: grid
columns: 3
cards:
- aspect_ratio: 1.5/1
color_type: card
entity: switch.roku
icon: mdi:gamepad-outline
name: Main TV
state:
- color: rgb(117,0,174)
value: 'on'
type: custom:button-card
conditions:
- entity: input_boolean.show_standard_cards
state: 'off'
type: conditional
- text: Virtual (template) Switches
type: custom:text-divider-row
- card:
type: entities
entities:
- entity: switch.roku_ultra_youtube_tv
name: YouTube TV
icon: mdi:youtube-tv
- entity: switch.roku_ultra_amazon
name: Amazon Prime
icon: mdi:alpha-a-circle
- entity: switch.roku_ultra_netflix
name: Netflix
icon: mdi:netflix
- entity: switch.roku_ultra_paramount
name: Paramount Plus
icon: mdi:alpha-p
- entity: switch.roku_ultra_live_tv
name: Roku Live TV
icon: mdi:television-box
- entity: switch.roku_ultra_tablo_tv
name: Tablo OTA TV
icon: mdi:video-input-antenna
- entity: switch.roku_ultra_youtube
name: YouTube
icon: mdi:youtube
- entity: switch.roku_ultra_peacock
name: Peacock Premium
icon: mdi:feather
conditions:
- entity: input_boolean.show_standard_cards
state: 'on'
type: conditional
- card:
square: false
type: grid
columns: 4
cards:
- type: custom:button-card
entity: switch.roku_ultra_youtube_tv
aspect_ratio: 1.2/1
color_type: card
color: rgb(0,200,0)
name: YouTube TV
entity_picture: /local/youtube_tv2.jpg
show_entity_picture: true
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(241,0,0)
value: 'on'
- color: rgb(0,0,0)
value: 'off'
- type: custom:button-card
entity: switch.roku_ultra_amazon
aspect_ratio: 1.2/1
color_type: card
name: Prime
entity_picture: /local/amazon_prime2.jpg
show_entity_picture: true
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(6,193,255)
value: 'on'
- color: rgb(0,0,0)
value: 'off'
- type: custom:button-card
entity: switch.roku_ultra_netflix
aspect_ratio: 1.2/1
color_type: card
name: Netflix
entity_picture: /local/netflix.jpg
show_entity_picture: true
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(152,16,27)
value: 'on'
- color: rgb(0,0,0)
value: 'off'
- type: custom:button-card
entity: switch.roku_ultra_paramount
aspect_ratio: 1.2/1
color_type: card
name: Paramount+
entity_picture: /local/paramount_plus.jpg
show_entity_picture: true
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(55,134,253)
value: 'on'
- color: rgb(0,0,0)
value: 'off'
- type: custom:button-card
entity: switch.roku_ultra_live_tv
aspect_ratio: 1.2/1
color_type: card
name: Roku Live TV
entity_picture: /local/roku_live.jpg
show_entity_picture: true
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(136,82,186)
value: 'on'
- color: rgb(0,0,0)
value: 'off'
- type: custom:button-card
entity: switch.roku_ultra_tablo_tv
aspect_ratio: 1.2/1
color_type: card
name: Tablo TV
entity_picture: /local/tablo.jpg
show_entity_picture: true
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(51,135,172)
value: 'on'
- color: rgb(0,0,0)
value: 'off'
- type: custom:button-card
entity: switch.roku_ultra_youtube
aspect_ratio: 1.2/1
color_type: card
name: YouTube
entity_picture: /local/youtube3.jpg
show_entity_picture: true
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(200,0,0)
value: 'on'
- color: rgb(0,0,0)
value: 'off'
- type: custom:button-card
entity: switch.roku_ultra_peacock
aspect_ratio: 1.2/1
color_type: card
name: Peacock
entity_picture: /local/peacock.jpg
show_entity_picture: true
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(55,255,120)
value: 'on'
- color: rgb(0,0,0)
value: 'off'
conditions:
- entity: input_boolean.show_standard_cards
state: 'off'
type: conditional
- type: vertical-stack
cards:
- text: Physical WLED Switch
type: custom:text-divider-row
- card:
type: entities
entities:
- entity: light.nano_leafs
name: WLED - Nano Leafs
icon: mdi:led-strip-variant
conditions:
- entity: input_boolean.show_standard_cards
state: 'on'
type: conditional
- card:
square: false
type: grid
cards:
- aspect_ratio: 1.5/1
color: rgb(2500,250,50)
color_type: card
name: WLED Display
entity: light.nano_leafs
show_name: true
show_state: false
state:
- color: rgb(50,50,50)
icon: mdi:led-strip-variant-off
value: 'off'
type: custom:button-card
columns: 3
conditions:
- entity: input_boolean.show_standard_cards
state: 'off'
type: conditional
- text: Virtual (template) Switches
type: custom:text-divider-row
- card:
type: entities
entities:
- entity: switch.nano_leafs_red
name: Solid Red
icon: mdi:alpha-r-circle
- entity: switch.nano_leafs_green
name: Solid Green
icon: mdi:alpha-g-circle
- entity: switch.nano_leafs_blue
name: Solid Blue
icon: mdi:alpha-b-circle
- entity: switch.nano_leafs_pink
name: Solid Pink
icon: mdi:alpha-p-circle
- entity: switch.nano_leafs_bouncing_balls
name: Bouncing Balls
icon: mdi:aurora
- entity: switch.nano_leafs_chase
name: Chase
icon: mdi:bike-fast
- entity: switch.nano_leafs_dancing_shadows
name: Dancing Shadows
icon: mdi:dance-ballroom
- entity: switch.nano_leafs_washing_machine
name: Washing Machine
icon: mdi:washing-machine
conditions:
- entity: input_boolean.show_standard_cards
state: 'on'
type: conditional
- card:
square: false
type: grid
cards:
- type: custom:button-card
entity: switch.nano_leafs_red
aspect_ratio: 1.2/1
color_type: card
color: rgb(0,200,0)
name: Red
icon: mdi:alpha-r-circle
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(255,0,0)
value: 'on'
- color: rgb(50,50,50)
value: 'off'
- type: custom:button-card
entity: switch.nano_leafs_green
aspect_ratio: 1.2/1
color_type: card
color: rgb(0,200,0)
name: Green
icon: mdi:alpha-g-circle
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(0,255,0)
value: 'on'
- color: rgb(50,50,50)
value: 'off'
- type: custom:button-card
entity: switch.nano_leafs_blue
aspect_ratio: 1.2/1
color_type: card
color: rgb(0,200,0)
name: Blue
icon: mdi:alpha-b-circle
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(0,0,255)
value: 'on'
- color: rgb(50,50,50)
value: 'off'
- type: custom:button-card
entity: switch.nano_leafs_pink
aspect_ratio: 1.2/1
color_type: card
color: rgb(0,200,0)
name: Pink
icon: mdi:alpha-p-circle
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(255,0,255)
value: 'on'
- color: rgb(50,50,50)
value: 'off'
- type: custom:button-card
entity: switch.nano_leafs_bouncing_balls
aspect_ratio: 1.2/1
color_type: card
color: rgb(0,200,0)
name: Bounce
icon: mdi:aurora
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(252,186,3)
value: 'on'
- color: rgb(50,50,50)
value: 'off'
- type: custom:button-card
entity: switch.nano_leafs_chase
aspect_ratio: 1.2/1
color_type: card
color: rgb(252,186,3)
name: Chase
icon: mdi:bike-fast
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(0,200,200)
value: 'on'
- color: rgb(50,50,50)
value: 'off'
- type: custom:button-card
entity: switch.nano_leafs_dancing_shadows
aspect_ratio: 1.2/1
color_type: card
color: rgb(252,186,3)
name: Dancing
icon: mdi:dance-ballroom
show_icon: true
tap_action:
action: toggle
state:
- color: rgb(86, 204, 92)
value: 'on'
- color: rgb(50,50,50)
value: 'off'
- type: custom:button-card
entity: switch.nano_leafs_washing_machine
aspect_ratio: 1.2/1
color_type: card
color: rgb(252,186,3)
name: Washing
icon: mdi:washing-machine
tap_action:
action: toggle
state:
- color: rgb(130, 60, 158)
value: 'on'
- color: rgb(50,50,50)
value: 'off'
columns: 4
conditions:
- entity: input_boolean.show_standard_cards
state: 'off'
type: conditional
- text: Input Boolean Option
type: custom:text-divider-row
- card:
type: entities
entities:
- entity: input_boolean.virtual_switch_trash
name: Take out Trash
icon: mdi:trash-can
- entity: input_boolean.virtual_switch_recycle
name: Take out Recyclables
icon: mdi:recycle
- entity: input_boolean.virtual_switch_dog
name: Walk the Dog
icon: mdi:dog-side
- entity: input_boolean.virtual_switch_dishes
name: Do the Dishes
icon: mdi:dishwasher
conditions:
- entity: input_boolean.show_standard_cards
state: 'on'
type: conditional
- card:
type: grid
square: false
columns: 4
cards:
- aspect_ratio: 1.2/1
color_type: card
entity: input_boolean.virtual_switch_trash
icon: mdi:trash-can
name: Trash
state:
- color: rgb(0,128,0)
value: 'on'
styles:
icon:
- animation: blink 2s ease infinite
type: custom:button-card
- aspect_ratio: 1.2/1
color_type: card
entity: input_boolean.virtual_switch_recycle
icon: mdi:recycle
name: Recyclables
state:
- color: rgb(200,200,0)
value: 'on'
styles:
icon:
- animation: blink 2s ease infinite
type: custom:button-card
- aspect_ratio: 1.2/1
color_type: card
entity: input_boolean.virtual_switch_dog
icon: mdi:dog-side
name: Walk Dog
state:
- color: rgb(0,128,128)
value: 'on'
styles:
icon:
- animation: blink 2s ease infinite
type: custom:button-card
- aspect_ratio: 1.2/1
color: rgb(0,255,0)
color_type: card
entity: input_boolean.virtual_switch_dishes
icon: mdi:dishwasher
name: Do Dishes
lock:
enabled: '[[[ return entity.state === "on"; ]]]'
unlock: hold
state:
- color: rgb(200,128,0)
value: 'on'
styles:
icon:
- animation: blink 2s ease infinite
type: custom:button-card
conditions:
- entity: input_boolean.show_standard_cards
state: 'off'
type: conditional
# ==============================================
# LIGHT DIMMING VIRTUAL SWITCH EXAMPLE
# Brightness attribute level may need to be
# adjusted for your particular situation/light
# ==============================================
switch:
- platform: template
switches:
lights_100:
value_template: “{{ is_state_attr('light.basement', 'brightness', 255) }}”
turn_on:
service: light.turn_on
target:
entity_id: light.basement
data:
brightness: 255
# I did not use the turn_off to prevent lights from turning off and back on when switching brightness levels
turn_off:
service: light.turn_off
target:
entity_id: light.basement
lights_75:
value_template: “{{ is_state_attr('light.basement', 'brightness', 191) }}”
turn_on:
service: light.turn_on
target:
entity_id: light.basement
data:
brightness: 191
lights_50:
value_template: “{{ is_state_attr('light.basement', 'brightness', 128) }}”
turn_on:
service: light.turn_on
target:
entity_id: light.basement
data:
brightness: 128
lights_25:
value_template: “{{ is_state_attr('light.basement', 'brightness', 64) }}”
turn_on:
service: light.turn_on
target:
entity_id: light.basement
data:
brightness: 64
# ======================================
# TV/STREAMING SERVICES EXAMPLE
# Only a few examples shown here.
# Repeat for any additional services
# for which you want to have a switch
# ======================================
switch:
- platform: template
switches:
prime_video:
value_template: "{{ is_state_attr('media_player.roku_ultra', ‘source’, ‘Prime Video’) }}"
turn_on:
– service: switch.turn_on
target:
entity_id: switch.roku_ultra
- service: media_player.select_source
target:
entity_id: media_player.roku_ultra
data:
source: ‘Prime Video’
turn_off:
- service: switch.turn_off
target:
entity_id: switch.roku_ultra
netflix:
value_template: "{{ is_state_attr('media_player.roku_ultra', ‘source’, ‘Netflix’) }}"
turn_on:
– service: switch.turn_on
target:
entity_id: switch.roku_ultra
- service: media_player.select_source
target:
entity_id: media_player.roku_ultra
data:
source: ‘Netflix’
turn_off:
- service: switch.turn_off
target:
entity_id: switch.roku_ultra
youtube_tv:
value_template: "{{ is_state_attr('media_player.roku_ultra', ‘source’, ‘YouTube TV’) }}"
turn_on:
– service: switch.turn_on
target:
entity_id: switch.roku_ultra
- service: media_player.select_source
target:
entity_id: media_player.roku_ultra
data:
source: ‘YouTube TV’
turn_off:
- service: switch.turn_off
target:
entity_id: switch.roku_ultra
# ==========================================
# WLED DISPLAY EXAMPLE
# Modify for your WLED entity name and the
# colors and/or effects for which you want
# to create switches.
# ==========================================
switch:
- platform: template
switches:
nano_leafs_red:
value_template: "{{ is_state_attr('light.nano_leafs', 'rgb_color', (255, 0, 0)) and is_state_attr('light.nano_leafs', 'effect', 'Solid') }}"
turn_on:
service: script.turn_on
entity_id: script.nano_leaf_red
turn_off:
service: light.turn_off
target:
entity_id: light.nano_leafs
nano_leafs_green:
value_template: "{{ is_state_attr('light.nano_leafs', 'rgb_color', (8, 255, 0)) and is_state_attr('light.nano_leafs', 'effect', 'Solid') }}"
turn_on:
service: script.turn_on
entity_id: script.nano_leaf_green
turn_off:
service: light.turn_off
target:
entity_id: light.nano_leafs
nano_leafs_blue:
value_template: "{{ is_state_attr('light.nano_leafs', 'rgb_color', (0, 0, 255)) and is_state_attr('light.nano_leafs', 'effect', 'Solid') }}"
turn_on:
service: script.turn_on
entity_id: script.nano_leaf_blue
turn_off:
service: light.turn_off
target:
entity_id: light.nano_leafs
nano_leafs_pink:
value_template: "{{ is_state_attr('light.nano_leafs', 'rgb_color', (255, 0, 255)) and is_state_attr('light.nano_leafs', 'effect', 'Solid') }}"
turn_on:
service: script.turn_on
entity_id: script.nano_leaf_pink
turn_off:
service: light.turn_off
target:
entity_id: light.nano_leafs
nano_leafs_bouncing_balls:
value_template: "{{ is_state_attr('light.nano_leafs', 'effect', 'Bouncing Balls') }}"
turn_on:
service: script.turn_on
entity_id: script.nano_leaf_bouncing_balls
turn_off:
service: script.turn_on
entity_id: script.nano_leaf_blue
nano_leafs_chase:
value_template: "{{ is_state_attr('light.nano_leafs', 'effect', 'Chase') }}"
turn_on:
service: script.turn_on
entity_id: script.nano_leaf_chase
turn_off:
service: script.turn_on
entity_id: script.nano_leaf_blue
nano_leafs_dancing_shadows:
value_template: "{{ is_state_attr('light.nano_leafs', 'effect', 'Dancing Shadows') }}"
turn_on:
service: script.turn_on
entity_id: script.nano_leaf_dancing_shadows
turn_off:
service: script.turn_on
entity_id: script.nano_leaf_blue
nano_leafs_washing_machine:
value_template: "{{ is_state_attr('light.nano_leafs', 'effect', 'Washing Machine') }}"
turn_on:
service: script.turn_on
entity_id: script.nano_leaf_washing_machine
turn_off:
service: script.turn_on
entity_id: script.nano_leaf_blue
# =======================================
# INPUT BOOLEAN EXAMPLES AND AUTOMATIONS
# These will need substantial modification
# for your own use, so these are to provide
# an outline for creating your own
# =======================================
input_boolean:
trash_day:
name: Trash Day
recycle_day:
name: Recycle Day
walk_dog:
name: Walk the Dog
do_dishes:
name: Do the Dishes
# -----------------------------------
# Example automations shown in video
# ------------------------------------
automation:
- alias: “Trash Day Tuesday”
trigger:
platform: time
at: “07:00:00”
condition:
condition: time
weekday:
- tue
action:
service: input_boolean.turn_on
target:
entity_id: input_boolean.trash_day
- alias: “Trash Day Notify”
trigger:
platform: state
entity_id: input_boolean.trash_day
from: ‘off’
to: ‘on’
condition:
action:
- service: light.turn_on
target:
entity_id: light.trash_day
- service: tts.google_say
entity_id:
- media_player.all_home_devices
data_template:
message: "Time to take out the trash."
- alias: “Walk the dog”
trigger:
- platform: time
at:
- “07:00:00”
- “12:00:00”
- “18:00:00”
condition:
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.walk_dog
- alias: Dishes Time
trigger:
platform: state
entity_id: input_boolean.do_dishes
from: ‘off’
to: ‘on’
action:
- service: tts.google.say
entity_id:
- media_player.all_home_devices
data_template:
message: “Time to do the dishes”
- delay: “00:05:00” # This should really use a timer and an automation for timer expiration for remaining steps
- service: tts.google.say
entity_id:
- media_player.all_home_devices
data_template:
message: “No TV until dishes are done”
- service: switch.turn_off
entity_id: switch.tv
- alias: Disable TV for Dishes
trigger:
platform: state
entity_id: switch.tv
from: ‘off’
to: ‘on’
condition:
condition: state
entity_id: input_boolean.do_dishes
state: ‘on’
action:
- service: tts.google.say
entity_id:
- media_player.all_home_devices
data_template:
message: “No TV until dishes are done”
- service: switch.turn_off
entity_id: switch.tv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment