Here’s what I am doing for my zwave switches to use tidy names in my config files. I don’t have dimmers, so this is just for switches.
Define the aliases I want in a text file at ~/.homeassistant/aliases/switch.txt
fairy_lights_switch_24_0 fairy_lights Fairy Lights
office_lights_spots_2_0 office_spotlights Office Spotlights
office_lights_pendant_2_0_2 office_pendant_light Office Pendant
garage_lights_fluorescents_23_0 garage_fluorescent_lights Garage Fluorescents
garage_lights_external_lantern_23_0_2 garage_external_light Garage Outside Light
Config generator at ~/.homeassistant/aliases/generate-switch-aliases.py
#!/usr/bin/env python
import re
import sys
header = """- platform: template
switches:"""
print(header)
regex = re.compile(r'(?P<fullname>[^\s]+)\s+(?P<alias>[^\s]+)\s+(?P<friendlyname>.+)?')
for line in sys.stdin:
m = regex.match(line)
fullname = m.group('fullname')
friendlyname = m.group('friendlyname')
alias = m.group('alias')
print(" %s:" % alias)
if friendlyname is not None:
print(" friendly_name: %s" % friendlyname)
print(" value_template: \"{{ is_state('switch.%s', 'on') }}\"" % fullname)
print(" entity_id:")
print(" - switch.%s" % fullname)
print(" turn_on:")
print(" service: switch.turn_on")
print(" entity_id: switch.%s" % fullname)
print(" turn_off:")
print(" service: switch.turn_off")
print(" entity_id: switch.%s" % fullname)
print("")
My configuration.yaml looks like this for switches:
switch: !include_dir_merge_list switches/
And i generate an aliases.yaml file like so:
cd ~/.homeassistant
chmod +x ./aliases/generate-switch-aliases.py
cat aliases/switch.txt | ./aliases/generate-switch-aliases.py > ./switches/aliases.yaml
This creates the ./switches/aliases.yaml
file, which looks like this:
- platform: template
switches:
fairy_lights:
friendly_name: Fairy Lights
value_template: "{{ is_state('switch.fairy_lights_switch_24_0', 'on') }}"
entity_id:
- switch.fairy_lights_switch_24_0
turn_on:
service: switch.turn_on
entity_id: switch.fairy_lights_switch_24_0
turn_off:
service: switch.turn_off
entity_id: switch.fairy_lights_switch_24_0
office_spotlights:
friendly_name: Office Spotlights
value_template: "{{ is_state('switch.office_lights_spots_2_0', 'on') }}"
entity_id:
- switch.office_lights_spots_2_0
turn_on:
service: switch.turn_on
entity_id: switch.office_lights_spots_2_0
turn_off:
service: switch.turn_off
entity_id: switch.office_lights_spots_2_0
etc...
Then replace every instance of the full zwave name with the new alias, eg replace switch.office_lights_spots_2_0
with switch.office_spotlights
I do the replacing automatically like this. (safe to run every time you change aliases, as long as you understand what it does!)
find . -name '*.yaml' ! -name 'aliases.yaml' -exec echo sed -i '' \
$(cat aliases/switch.txt | while read fullname aliasname friendly ; \
do echo -n "-e 's/$fullname/$aliasname/g' " ; done) {} + | bash
If I or someone else ever bother to bake the device name/aliasing into the zwave component properly, i’ll remove my switches/aliases.yaml file and name them via the zwave component somehow.
I’m content with this setup for now - if i have to replace a zwave switch, or change whatever tech I’m using to control the lights, I can keep using the same switch name in hass. And my config files read a lot better