Entity_id: switch. with input_select. in Automation

Hi!

I’m trying to use the output of a ’nput_select to switch on switch.
I have the following in configuration.yaml:

input_select:
  consumer_solar_power:
    name: Consumer
    icon: mdi:consolidate
    options:
      - "cumulus"
      - "car"
      - "deshumi"

then in the Automation:

alias: Test Automation
description: ""
trigger:
  - id: "on"
    platform: numeric_state
    entity_id: sensor.net_enphase_watt_now
    above: input_number.solar_power_on
  - id: "off"
    platform: numeric_state
    entity_id: sensor.net_enphase_watt_now
    below: input_number.solar_power_off
condition: []
action:
  - service: switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.{{ input_select.consumer_solar_power }}
mode: single

The 1st part with the trigger.id is working fine, this has been tested with a hardcoded switch but I can get the intity_id, it throws the following:

Error: Error rendering service target template: UndefinedError: 'input_select' is undefined

Thank you in advance for anyone who could share some pointers!

Raphaël

Easy fix.

      entity_id: "switch.{{ states('input_select.consumer_solar_power') }}"

Get the input_select’s value using the states function.

1 Like