Hi, if possible I would like some help with templates, the code below works fine, I can select from the front end which light I want associated with my wifi IOT button, push the button and it toggles the associated light …
is there a way using a template to make the code more eloquent rather than having multiple automations, I’ve tried but I just can’t get my head around the template format and need some pointers.
Thanks
Config yaml:
sensor:
- platform: mqtt
name: “wifi_IOT”
state_topic: “wifi_button_1”
input_select:
wifi_button_1_mode:
name: WIFI Button mode
options:
- “Bedroom Light”
- “Computer Light”
- “Dinning Room Light”
- “Outside Lights”
icon: mdi:target
Automation yaml:
-
alias: “WIFI IOT Button Computer”
hide_entity: true
trigger:- platform: state
entity_id: sensor.wifi_iot
to: ‘connected’
condition:
condition: state
entity_id: input_select.wifi_button_1_mode
state: “Computer Light”
action:
- service: homeassistant.toggle
entity_id: switch.computer_lamp
- platform: state
-
alias: “WIFI IOT Button Dinning room”
hide_entity: true
trigger:- platform: state
entity_id: sensor.wifi_iot
to: ‘connected’
condition:
condition: state
entity_id: input_select.wifi_button_1_mode
state: “Dinning Room Light”
action:
- service: homeassistant.toggle
entity_id: switch.dinning_room
- platform: state
-
alias: “WIFI IOT Button Outside Lights”
hide_entity: true
trigger:- platform: state
entity_id: sensor.wifi_iot
to: ‘connected’
condition:
condition: state
entity_id: input_select.wifi_button_1_mode
state: “Outside Lights”
action:
- platform: state
-
service: homeassistant.toggle
entity_id: switch.outside_lights -
alias: “WIFI IOT Button Bedroom Light”
hide_entity: true
trigger:- platform: state
entity_id: sensor.wifi_iot
to: ‘connected’
condition:
condition: state
entity_id: input_select.wifi_button_1_mode
state: “Bedroom Light”
action:
- platform: state
-
service: homeassistant.toggle
entity_id: switch.bedroom_lamp