From 2086260bf3d9d027d60bb7502806b95ca40ac495 Mon Sep 17 00:00:00 2001 From: Christian Elberfeld <christian.elberfeld@adesso.de> Date: Sat, 2 Oct 2021 23:27:56 +0200 Subject: [PATCH] mqtt sensoren --- host_vars/warpsrvint | 7 +++++ warpsrvint/docker_openhab/tasks/main.yml | 3 ++ .../templates/conf/items/groups.items | 2 +- .../templates/conf/items/mqtt.items | 25 +++++++++++++++++ .../templates/conf/services/mqtt.cfg | 0 .../templates/conf/things/mqtt.things | 28 +++++++++++++++++++ 6 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 warpsrvint/docker_openhab/templates/conf/items/mqtt.items create mode 100644 warpsrvint/docker_openhab/templates/conf/services/mqtt.cfg create mode 100644 warpsrvint/docker_openhab/templates/conf/things/mqtt.things diff --git a/host_vars/warpsrvint b/host_vars/warpsrvint index 661972bc..1294e6c1 100644 --- a/host_vars/warpsrvint +++ b/host_vars/warpsrvint @@ -114,3 +114,10 @@ borgbackup_user: sshkeys: - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIENYus4S4XOaGHVL4B6vbnIrovtqaCT1lbEF73StiTt+ root@webserver" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGIBBvcQaD0MmEHY0q+lcoMN9sXHs/HnSiXGsAhm+Vwp root@vorstand" + +mqtt_sensors_temp: + - { id: "hauptraum", name: "Hauptraum", groups: "gHauptraum" } + - { id: "vortragsraum", name: "Vortragsraum", groups: "gVortragsraum" } + +mqtt_sensors_feinstaub: + - { id: "feinstaub01", name: "Feinstaub01", groups: "gHauptraum" } diff --git a/warpsrvint/docker_openhab/tasks/main.yml b/warpsrvint/docker_openhab/tasks/main.yml index 30304e0f..9e96c941 100644 --- a/warpsrvint/docker_openhab/tasks/main.yml +++ b/warpsrvint/docker_openhab/tasks/main.yml @@ -52,6 +52,7 @@ dest: "/srv/openhab/{{ item }}" with_items: - conf/items/groups.items + - conf/items/mqtt.items - conf/items/network.items - conf/items/other.items - conf/items/weather.items @@ -59,9 +60,11 @@ - conf/persistence/rrd4j.persist - conf/services/addons.cfg - conf/services/influxdb.cfg + - conf/services/mqtt.cfg - conf/services/network.cfg - conf/services/runtime.cfg - conf/things/astro.things + - conf/things/mqtt.things - conf/things/network.things - conf/things/weather.things diff --git a/warpsrvint/docker_openhab/templates/conf/items/groups.items b/warpsrvint/docker_openhab/templates/conf/items/groups.items index ac6d66b1..33156420 100644 --- a/warpsrvint/docker_openhab/templates/conf/items/groups.items +++ b/warpsrvint/docker_openhab/templates/conf/items/groups.items @@ -4,8 +4,8 @@ // Liste der Icons: https://www.openhab.org/docs/configuration/iconsets/classic/ // Liste der Semantic Tags: https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.semantics/model/SemanticTags.csv -Group gEWerkstatt "EWerkstatt" <settings> ["GuestRoom"] Group gFlur "Flur" <corridor> ["Corridor"] +Group gHauptraum "Hauptraum" <settings> ["GuestRoom"] Group gHolzwerkstatt "Holzwerkstatt" <settings> ["GuestRoom"] Group gKueche "Küche" <kitchen> ["Kitchen"] Group gLounge "Lounge" <sofa> ["LivingRoom"] diff --git a/warpsrvint/docker_openhab/templates/conf/items/mqtt.items b/warpsrvint/docker_openhab/templates/conf/items/mqtt.items new file mode 100644 index 00000000..0c9c3786 --- /dev/null +++ b/warpsrvint/docker_openhab/templates/conf/items/mqtt.items @@ -0,0 +1,25 @@ + +{% for device in mqtt_sensors_temp %} + +Number MQTT_{{ device.id }}_temp "Sensor {{ device.name }} Temp [%.1f °C]" <temperature> ({{ device.groups }}) ["Measurement","Temperature","CurrentTemperature"] { + channel="mqtt:topic:mosquitto:{{ device.id }}:temp" +} + +Number MQTT_{{ device.id }}_pressure "Sensor {{ device.name }} Pressure [%.1f hPa]" <pressure> ({{ device.groups }}) ["Measurement","Pressure"] { + channel="mqtt:topic:mosquitto:{{ device.id }}:pressure" +} + +Number MQTT_{{ device.id }}_humidity "Sensor {{ device.name }} Humidity [%.1f %%]" <humidity> ({{ device.groups }}) ["Measurement","Humidity","CurrentHumidity"] { + channel="mqtt:topic:mosquitto:{{ device.id }}:humidity" +} + +{% endfor %} + +{% for device in mqtt_sensors_feinstaub %} + +Number MQTT_{{ device.id }}_feinstaub_2_5 "Sensor {{ device.name }} 2.5 PM [%.1f µg/m³]" ({{ device.groups }}) ["Measurement"] { + channel="mqtt:topic:mosquitto:{{ device.id }}:feinstaub_2_5" +} + +{% endfor %} + diff --git a/warpsrvint/docker_openhab/templates/conf/services/mqtt.cfg b/warpsrvint/docker_openhab/templates/conf/services/mqtt.cfg new file mode 100644 index 00000000..e69de29b diff --git a/warpsrvint/docker_openhab/templates/conf/things/mqtt.things b/warpsrvint/docker_openhab/templates/conf/things/mqtt.things new file mode 100644 index 00000000..8c49e918 --- /dev/null +++ b/warpsrvint/docker_openhab/templates/conf/things/mqtt.things @@ -0,0 +1,28 @@ + +Bridge mqtt:broker:mosquitto [ host="{{ int_ip4 }}", secure=false, enableDiscovery=false ] +{ + +{% for device in mqtt_sensors_temp %} + + Thing topic {{ device.id }} { + Channels: + Type number : temp "Sensor {{ device.name }} Temp" [ stateTopic="ESPHome/esphome_{{ device.id }}/sensor/temp/state" ] + Type number : pressure "Sensor {{ device.name }} Pressure" [ stateTopic="ESPHome/esphome_{{ device.id }}/sensor/pressure/state" ] + Type number : humidity "Sensor {{ device.name }} Humidity" [ stateTopic="ESPHome/esphome_{{ device.id }}/sensor/humidity/state" ] + } + + +{% endfor %} + +{% for device in mqtt_sensors_feinstaub %} + + Thing topic {{ device.id }} { + Channels: + Type number : feinstaub_2_5 "Sensor {{ device.name }} 2.5 PM" [ stateTopic="ESPHome/esphome_{{ device.id }}/sensor/feinstaub_2_5/state" ] + } + + +{% endfor %} + +} + -- GitLab