Refactor mqtt topics for shelly plugs

This commit is contained in:
Timo Makinen 2025-04-05 17:37:56 +00:00
parent 95c66d976f
commit d6cc79dcb3
3 changed files with 10 additions and 5 deletions

View file

@ -2,7 +2,7 @@
sensor:
{% for shelly in shellies | selectattr("name", "match", "^shellyplug-s-") | list %}
- name: Power Usage
state_topic: home/{{ shelly["room"] }}/{{ shelly["device"] }}/relay/0/power
state_topic: home/{{ shelly["room"] }}/{{ shelly["device"] }}/power
unique_id: {{ shelly["name"] }}
unit_of_measurement: W
device:

View file

@ -12,5 +12,10 @@ bridge_certfile {{ tls_certs }}/{{ inventory_hostname }}.crt
bridge_keyfile {{ tls_private }}/{{ inventory_hostname }}.key
{% for shelly in shellies %}
{% if shelly['name'] | regex_search("^shellyplug-s-") %}
topic power out 0 shellies/{{ shelly['name'] }}/relay/0/ home/{{ shelly['room'] }}/{{ shelly['device'] }}/
topic temperature out 0 shellies/{{ shelly['name'] }}/ home/{{ shelly['room'] }}/{{ shelly['device'] }}/
{% else %}
topic # out 0 shellies/{{ shelly['name'] }}/ home/{{ shelly['room'] }}/{{ shelly['device'] }}/
{% endif %}
{% endfor %}

View file

@ -10,7 +10,7 @@
tls_cert = "{{ tls_certs }}/{{ inventory_hostname }}.crt"
tls_key = "{{ tls_private }}/{{ inventory_hostname }}.key"
topics = [
"+/+/+/relay/0/power",
"+/+/+/power",
"+/+/+/temperature",
"+/+/+/sensor/battery",
"+/+/+/sensor/lux",
@ -21,9 +21,9 @@
data_format = "value"
[[inputs.mqtt_consumer.topic_parsing]]
topic = "+/+/+/relay/0/power"
tags = "location/room/device/_/_/_"
measurement = "_/_/_/_/_/measurement"
topic = "+/+/+/power"
tags = "location/room/device/_"
measurement = "_/_/_/power"
[[inputs.mqtt_consumer.topic_parsing]]
topic = "+/+/+/temperature"