Mode switch/Input select button redering

mode

Is it possible to make a mode switch in HA (without Custom UI etc.)?
Or make an Input Select component, - rendered like buttons?

The point of this is to have one selected all the time, and the other options deselected. When another is selected, the others are deselected.

1 Like

You mean something like tiles?

Yes. But native HA (no custom code)

I am a bit baffled that HA lacks some basic functionality. As the N00b I am…

Well, that depends on your needs and expectations. I don’t miss tiles myself.

Other people have created custom UI and/or HA dashboard. You can always use these or develop your own code. That is the great thing about open source software.

You are absoIurly right. I second that. It’s a matter of opinion what basic functionality is.

I am impressed by this community and what they com up with!

So hopefully with time more functionality is implemented so one do not need several custom packages to maintain

What do you know…Shame on me!
This was easily done with standard Ha code. All smile!

giphy

4 Likes

Hi @Tomahawk, can I know how did you manage to make this work ? if you could share your config would appreciate it.

Thank You

This code is a workaround since HA does not have “radio button list” options.
https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio

#File:input boolean
####################################################
# HA MODES                                         #
####################################################

ha_mode_home:
  name: Home
  icon: mdi:home-account

ha_mode_away:
  name: Away
  icon: mdi:walk

ha_mode_night:
  name: Night
  icon: mdi:weather-night

ha_mode_holiday:
  name: Holiday 
  icon: mdi:airplane-takeoff

#File: Sensors
####################################################
# HA MODE SENSOR                                   #
####################################################

  - platform: template
    sensors:
      ha_mode:
        friendly_name: 'HA Mode'
        entity_id: input_boolean.ha_mode_home,
                   input_boolean.ha_mode_away,
                   input_boolean.ha_mode_holiday, 
                   input_boolean.ha_mode_night
        value_template: >-
         {% if is_state('input_boolean.ha_mode_home', 'on') %}
            home
         {% elif is_state('input_boolean.ha_mode_away', 'on') %}
            away
         {% elif is_state('input_boolean.ha_mode_night', 'on') %}
           night
         {% elif is_state('input_boolean.ha_mode_holiday', 'on') %}
           holiday
         {% endif %}
        icon_template: >-
          {% if is_state('input_boolean.ha_mode_home', 'on') %}
             mdi:home-account
          {% elif is_state('input_boolean.ha_mode_away', 'on') %}
             mdi:walk
          {% elif is_state('input_boolean.ha_mode_night', 'on') %}
             mdi:weather-night
          {% elif is_state('input_boolean.ha_mode_holiday', 'on') %}
            mdi:airplane-takeoff
          {% endif %}

#File: Binary sensor
####################################################
# HA MODE SENSOR Display only                      #
####################################################

  - platform: template
    sensors:
      ha_mode:
        friendly_name: "HA Mode"
        entity_id: sensor.ha_mode
        value_template: >-
          {{ is_state('sensor.ha_mode', 'home') 
             or is_state('sensor.ha_mode', 'away')
             or is_state('sensor.ha_mode', 'night')
             or is_state('sensor.ha_mode', 'holiday') }}
        icon_template: >-
          {% if is_state('sensor.ha_mode', 'home') %}
             mdi:home-account
          {% elif is_state('sensor.ha_mode', 'away') %}
             mdi:walk
          {% elif is_state('sensor.ha_mode', 'night') %}
             mdi:weather-night
          {% elif is_state('sensor.ha_mode', 'holiday') %}
            mdi:airplane-takeoff
          {% endif %}

#File: Automation
#######################################################################
#  HA MODE SET SCENES                                                 #
#######################################################################

- alias: HA Mode set
  trigger:
    platform: state
    entity_id: input_boolean.ha_mode_home,
               input_boolean.ha_mode_away,
               input_boolean.ha_mode_holiday, 
               input_boolean.ha_mode_night
    to: 'on'
  action:
    - service: input_boolean.turn_off
      data_template:
        entity_id: >
          {% set booleans = [ 'input_boolean.ha_mode_home', 'input_boolean.ha_mode_away', 'input_boolean.ha_mode_holiday', 'input_boolean.ha_mode_night' ] | reject('equalto', trigger.entity_id) %}
          {{ booleans | list | join(', ') }}
5 Likes

@Tomahawk awesome, thank you :slight_smile: I’m new with HA, this would help a lot.

I was testing your example (am actually using a ‘fork’), and noticed that you can switch off all input booleans. Which will render the sensor.ha_mode empty. This would mean an unknown mode.

Have you considered how to catch this? There are a few options:

  • leave it as it is
  • use the automation (or a second one) to force/set a default (‘home’)
  • if all booleans are ‘off’, then switch to ‘away’ if the last state was ‘home’, otherwise switch to ‘home’.

What do you think?

I decided to leave it as is.
A second automation setting a specific mode if all sensor are set to off would my choice.

And hope for the HA team to implement a radiobutton list with time.

The new Lovelace UI should be able to render an input select to a radio button, I guess.

Hi Tomahawk,
thanks for your code. I copied it into my beginners configuration. And I have several newbie questions:

  • Is there a way to order the icons (Day / Night / Away / Vacation)?
  • How could I get rid of the Automatiserung-Widget?
  • How could rename the widget “Boolsche Eingabe”? I have no idea where the name came from?

Screenshot

In your grop.yaml-file, order the list at your choice:

  ha_mode:
    name: Mode
    control: hidden
    entities:
      - input_boolean.ha_mode_home
      - input_boolean.ha_mode_away
      - input_boolean.ha_mode_night
      - input_boolean.ha_mode_holiday

In your grop.yaml-file, remove the entry. -automation.Automatiserung-Widget(?)

In your grop.yaml-file, add name: XYZ to your ha_mode:

  ha_mode:
    name: Mode  
    control: hidden
    entities:
      - input_boolean.ha_mode_home
      - input_boolean.ha_mode_away
      - input_boolean.ha_mode_night
      - input_boolean.ha_mode_holiday
1 Like

I do not have an entry for the automation-Widget in the group.yaml-file… But, with your hints I made 75% of my wished :grinning:

After entering your group hints, I have two sensor in the header line listed, which I do not really understand.
Screenshot

If you have the default setup, I believe your automations and your sensors will show up by default in your GUI.
If you start organizing your group.yaml-file, with your own declared default view, you will have total control of what and how items are displayed.

#############################################################
# DEFAULT VIEW    groups.yaml                                          #
#############################################################
  default_view:
    name: Home
    view: yes
    icon: mdi:home
    entities:
      - binary_sensor.ha_mode
      - sensor.moonphases
      - sensor.weather_symbol_text
      - sensor.weather_temp_feel
      - sensor.weather_temperature
      - sensor.weather_wind_speed
      - sensor.wind_compass
      - sensor.sunrise_today
      - sensor.sundaylight_today
      - sensor.sunset_today
      - sensor.nilu_air_pollution_outside
      - sensor.nilu_oslo_manglerud_max
      - group.entre
      - group.stue
      - group.kjokken
      - group.baderom
      - group.soverom
      - group.loft

  loft:
    name: Loft
    entities:
      - zwave.fib_smoke_sensor3
      - sensor.fib_smoke_sensor3_temperature
      - zwave._fib_flood_sensor1
      - switch.switch_water_boiler
#      - sensor.fib_flood_sensor1_temperature

etc..

#############################################################
# AUDIO/VIDE VIEW                                           #
#############################################################

  audio_video_view:
    name: Audio/Video
    view: yes
    icon: mdi:audio-video
    entities:
      - group.nas_home
      - media_player.stue

  nas_home:
    name: NAS
    control: hidden
    entities:
      - switch.nas411_wol

There are in addition to the four “button”-sensors, two other sensors:

  1. binary_sensor.ha_mode, is just for display in the GUI so when a button is selected, the correct icon will be displayed in yellow (when you click on it).

  2. sensor.ha_mode, is for storing the button-value selected for using in later logic like scenes etc…

in witch files do i have to paste the parts of the config you shared?

thanks in advance!

Look at the code and you will see #File: «the file name»

Thank you verry much, it’s working fine at the moment and i can select a mode!

now i have the folowing problem, I’m having the same switch as the picture above and trying to set the mode by the 2-wall switch. it’s sending 2 codes. code 1 on and off and code 2 on and off.

What am i doing wrong and how do i get this thing work?

I have made the following code for it;

  • alias: thuis (home) stand inschakelen
    trigger:
    platform: state
    entity_id: switch.modus_schakelaar_thuis_of_slapen_gang_beneden
    to: ‘on’
    action:
    service: input_boolean.turn_on
    entity_id: input_boolean.ha_mode_home

  • alias: Slapen (night) stand inschakelen
    trigger:
    platform: state
    entity_id: switch.modus_schakelaar_thuis_of_slapen_gang_beneden
    to: ‘off’
    action:
    service: input_boolean.turn_on
    entity_id: input_boolean.ha_mode_night

  • alias: Afwezig (away) stand inschakelen
    trigger:
    platform: state
    entity_id: switch.modus_schakelaar_afwezig_of_vakantie_gang_beneden
    to: ‘on’
    action:
    service: input_boolean.turn_on
    entity_id: input_boolean.ha_mode_away

  • alias: Vakantie (holiday) stand inschakelen
    trigger:
    platform: state
    entity_id: switch.modus_schakelaar_thuis_of_slapen_gang_beneden
    to: ‘off’
    action:
    service: input_boolean.turn_on
    entity_id: input_boolean.ha_mode_holiday

thanks in advance!

I don’t understand this sentence (?). But I read it like a switch can have an "on" and "off" state. And you have two of these.

Try:
from: ‘off’
to: ‘on’

Please format your code with the “</>”-button like:

- alias: thuis (home) stand inschakelen
  trigger:
    platform: state
    entity_id: switch.modus_schakelaar_thuis_of_slapen_gang_beneden
    to: 'on'
  action:
    service: input_boolean.turn_on
    entity_id: input_boolean.ha_mode_home

I don’t see anything wrong with your code.