Map values for an input_select?

good catch!
didn’t help though…
test results so far:

secret with variable to secrets file: check, working fine (hadn’t done that before, so good to know)
template for id: check! working fine.

now testing template for sensitivity chichis a bit more of a challenge, though I see I had quoted the template and it should really be:

      `{"sensitivity": {{states('input_select.select_hue_sensitivity')}} }`

Update

Bingo!!:

I can report Ive got it working as hoped for, and made a few testing sensors to show it does, like:

- platform: command_line
  name: Laundry sensitivity
  command: curl -X GET http://192.168.1.212/api/API/sensors/22
  value_template: >
    {{ value_json.config.sensitivity }}

44
35
36

new package, fully functional, with added sensors and a new Mapper for sensitivity:

##############################################################################################################
# Package Hue sensitivity by @mariusthvdb
# see community discussion on https://community.home-assistant.io/t/map-values-for-an-input-select/94354/5
# and https://community.home-assistant.io/t/hue-motion-sensors-remotes-custom-component/27176/687?u=mariusthvdb
# big help by @pnbruckner @Martso @cicero222 and @petro. @123 filed a feature request for the mappings on
# https://community.home-assistant.io/t/input-select-enhancement-support-maps-key-value-pairs/94391
# jan 25 2019
##############################################################################################################

homeassistant:
  customize:
    script.set_hue_sensitivity:
      action_name: 'Set'
      icon: mdi:settings

    input_select.select_hue_sensitivity:
      templates:
        icon: >
          if (state === 'Low') return 'mdi:numeric-0-box-multiple-outline';
          if (state === 'Medium') return 'mdi:numeric-1-box-multiple-outline';
          return 'mdi:numeric-2-box-multiple-outline';
        icon_color: >
          if (state === 'Low') return 'grey';
          if (state === 'Medium') return 'blue';
          return 'red';

    sensor.laundry_sensitivity:
      templates:
        icon: >
          if (state === '0') return 'mdi:numeric-0-box-multiple-outline';
          if (state === '1') return 'mdi:numeric-1-box-multiple-outline';
          return 'mdi:numeric-2-box-multiple-outline';
        icon_color: >
          if (state === '0') return 'grey';
          if (state === '1') return 'blue';
          return 'red';

    sensor.auditorium_sensitivity:
      templates:
        icon: >
          if (state === '0') return 'mdi:numeric-0-box-multiple-outline';
          if (state === '1') return 'mdi:numeric-1-box-multiple-outline';
          return 'mdi:numeric-2-box-multiple-outline';
        icon_color: >
          if (state === '0') return 'grey';
          if (state === '1') return 'blue';
          return 'red';

##############################################################################################################
# Scripts and Commands
##############################################################################################################
# https://community.home-assistant.io/t/hue-motion-sensors-remotes-custom-component/27176/698?u=mariusthvdb
rest_command:
  set_hue_command: #not named sensitivy because the command can be used to set other entities/attributes also
    url: !secret url_set_hue_command
    method: put
    payload: '{{ data }}'

script:
  set_hue_sensitivity:
    alias: Set Hue sensitivity
    sequence:
      service: rest_command.set_hue_command
      data_template:
        command: config
        type: sensors
        data: >
          {% set mapper =
            { 'Low':'0',
              'Medium':'1',
              'High':'2' } %}
          {% set state = states('input_select.select_hue_sensitivity') %}
          {% set sensitivity = mapper[state] if state in mapper %}
          {"sensitivity": {{sensitivity}} }
        id: >
          {% set mapper =
            { 'Laundry':'22',
              'Dining table':'52',
              'Auditorium':'44',
              'Frontdoor':'60',
              'Dorm':'56',
              'Corridor':'5',
              'Corridor terrace':'33',
              'Master bedroom':'48',
              'Corridor Office':'28',
              'Control room':'7',
              'Attic':'12' } %}
          {% set state = states('input_select.select_hue_motion_sensor') %}
          {% set id = mapper[state] if state in mapper %}
          {{id}}


##############################################################################################################
# Inputs
##############################################################################################################

input_select:
  select_hue_sensitivity:
    name: select Hue sensitivity
    options:
      - Low
      - Medium
      - High

  select_hue_motion_sensor:
    name: select Motion sensor
    icon: mdi:run-fast
    options:
      - Laundry
      - Dining table
      - Auditorium
      - Frontdoor
      - Dorm
      - Corridor
      - Corridor terrace
      - Master bedroom
      - Corridor Office
      - Control room
      - Attic

##############################################################################################################
# Sensors
##############################################################################################################
sensor:
  - platform: command_line
    name: Laundry sensitivity
    command: !secret get_laundry_config
    value_template: >
      {{ value_json.config.sensitivity }}

  - platform: command_line
    name: Auditorium sensitivity
    command: !secret get_auditorium_config
    value_template: >
      {{ value_json.config.sensitivity }}

##############################################################################################################
# Groups
##############################################################################################################

group:
  set_hue_sensor_sensitivity:
    icon: mdi:run-fast
    control: hidden
    name: Set Hue sensor sensitivity
    entities:
      - sensor.laundry_sensitivity
      - sensor.auditorium_sensitivity
      - input_select.select_hue_motion_sensor
      - input_select.select_hue_sensitivity
      - script.set_hue_sensitivity

##############################################################################################################
# Notes
##############################################################################################################

UPDATE

with Tiles, mimicking the Hue App:

42

2 Likes