What I am aiming to do is to send along with the /config discovery payload additional data such as a device name that can be used in lovelace.
I have a fully functional custom relay bank device (nodejs code) sending the mqtt config discovery payloads for each relay to HA. That’s all working fine.
In my backend/device I have a yaml file that configures the hardware and sets an id and name/alias for each relay.
solenoids:
- id: zone_1
relay: 1
alias: Front Yard North
gpio: 80
- id: zone_2
relay: 2
alias: Front Yard South
gpio: 73
- id: zone_3
relay: 3
alias: Front Yard Beds
gpio: 69
...
so my nodejs backend code publishes payloads like so to the /config topic
------ sending discovery payload to HA for Front Yard North : zone_1 -----
topic=> homeassistant/switch/irrigation/zone_1/config
'{"name":"irrigation_zone_1","command_topic":"homeassistant/switch/irrigation/zone_1/set","state_topic":"homeassistant/switch/irrigation/zone_1/state"}'
In the front end (lovelace) i use this jinja2/yaml to generate the cards
# lovelace_gen
{% set zones = {
'1':'Front Yard North',
'2':'Front Yard South',
'3':'Front Yard Beds',
'4':'Back Yard East Spigot',
'5':'Back Yard Garage Spigot',
'6':'Back Yard West Spigot',
'7':'Garden East',
'8':'Garden West'
}
%}
icon: mdi:water
cards:
- type: vertical-stack
cards:
- type: markdown
content: >
# Irrigation
{# - type: horizontal-stack
cards: #}
{% for zone,name in zones.items() %}
- type: entity-button
entity: switch.irrigation_zone_{{ zone }}
icon: mdi:water
name: {{ name }}
tap_action:
action: toggle
{% endfor %}
as you see I have “hard coded” in the lovelace yaml the alias names of my entities and used those in the entity name prop. That is not ideal. I would like to get those aliases from the backend yaml to use in lovelace
I thought I could attach extra data in the device key of the mqtt switch in the config payload but whenever I do that HA fails to discover the entity
{"name":"irrigation_zone_5","device":{"manufactuerer":"uci","name":"Back Yard Garage Spigot"},"command_topic":"homeassistant/switch/irrigation/zone_5/set","state_topic":"homeassistant/switch/irrigation/zone_5/state"}
let payload = {
name:`${opts.namespace || NAMESPACE ? `${opts.namespace || NAMESPACE }_` :''}${ent.id}`,
device: { // here I try to add the device key to the json but it causes entity not to be discovered
manufacturer : 'uci',
name: ent.alias,
},
command_topic:`${topic}/${opts.command || COMMAND_TOPIC}`,
state_topic: `${topic}/${opts.state || STATE_TOPIC}`
}
So how can I get additional data from my device (either in the config payload or via another topic - mqtt sensor?) to the HA frontend (lovelave) for use in the jinja template? (or HA template)?