diff --git a/roles/homeassistant/tasks/main.yml b/roles/homeassistant/tasks/main.yml index ab6bc4f..d76b79d 100644 --- a/roles/homeassistant/tasks/main.yml +++ b/roles/homeassistant/tasks/main.yml @@ -145,6 +145,16 @@ group: "{{ ansible_wheel }}" setype: _default +- name: Create mqtt config file + ansible.builtin.template: + dest: /srv/homeassistant/mqtt.yaml + src: mqtt.yaml.j2 + mode: "0644" + owner: root + group: "{{ ansible_wheel }}" + setype: _default + notify: Restart homeassistant + - name: Create directories for custom integrations ansible.builtin.file: path: "{{ item }}" diff --git a/roles/homeassistant/templates/mqtt.yaml.j2 b/roles/homeassistant/templates/mqtt.yaml.j2 new file mode 100644 index 0000000..8d70762 --- /dev/null +++ b/roles/homeassistant/templates/mqtt.yaml.j2 @@ -0,0 +1,13 @@ +--- +sensor: +{% for shelly in shellies | selectattr("name", "match", "^shellyplug-s-") | list %} + - name: Power Usage + state_topic: home/{{ shelly["room"] }}/{{ shelly["device"] }}/relay/0/power + unique_id: {{ shelly["name"] }} + unit_of_measurement: W + device: + name: {{ shelly["device"] | capitalize }} + suggested_area: {{ shelly["room"] | replace("_", " ") | capitalize }} + identifiers: + - {{ shelly["name"] }} +{% endfor %}