Dear All,
i have been trying now for more than one week but unfortunately have not suceeded yet, so i am asking you for help:
I am working on a LORAWAN automation an receive packages over MQTT.
The packages look like this:
{"deduplicationId":"xyz","time":"2025-01-24T06:08:03.175745+00:00","deviceInfo":{"tenantId":"xyz","tenantName":"ChirpStack","applicationId":"xyz","applicationName":"xyz","deviceProfileId":"xyz","deviceProfileName":"door","deviceName":"doorsensor","devEui":"xyz","deviceClassEnabled":"CLASS_A","tags":{}},"devAddr":"01a3554b","adr":false,"dr":0,"fCnt":63,"fPort":10,"confirmed":false,"data":"DDABAAAlAAAAAA==","object":{"MOD":1.0,"LAST_DOOR_OPEN_DURATION":0.0,"ALARM":0.0,"DOOR_OPEN_TIMES":37.0,"DOOR_OPEN_STATUS":0.0,"BAT_V":3.12},"rxInfo":[{"gatewayId":"xyz","uplinkId":16660,"gwTime":"2025-01-24T06:08:03.175745+00:00","rssi":-90,"snr":10.5,"channel":5,"location":{},"context":"4VsnzA==","crcStatus":"CRC_OK"}],"txInfo":{"frequency":867500000,"modulation":{"lora":{"bandwidth":125000,"spreadingFactor":12,"codeRate":"CR_4_5"}}},"regionConfigId":"eu868"}
The important information are contained in the "object-part:
"object":{"MOD":1.0,"LAST_DOOR_OPEN_DURATION":0.0,"ALARM":0.0,"DOOR_OPEN_TIMES":37.0,"DOOR_OPEN_STATUS":0.0,"BAT_V":3.12}
In order to handle the information i have created a sensor in my configuration.yaml:
mqtt:
sensor:
- name: "Door_state"
unique_id: lorawan_state
state_topic: "xyz"
value_template: >
{% if is_state('value_json.object.DOOR_OPEN_STATUS','1.0') %} open
{% else %} closed
{% endif %}
device:
identifiers: lorawan_door
manufacturer: Dragino
name: LDS02
- name: "Door_Voltage"
unique_id: lorawan_battery
state_topic: "xyz"
value_template: "{{ value_json.object.BAT_V }}"
unit_of_measurement: "V"
device:
identifiers: lorawan_door
manufacturer: Dragino
name: LDS02
The battery voltage is working like a charme, but i do not get the values for the state translated into “open/closed”.
Just coding "value_template: “{{ value_json.object.DOOR_OPEN_STATUS }}” is handing over correctly the “1.0” or “0.0”
mqtt:
sensor:
- name: "Door_state"
unique_id: lorawan_state
state_topic: "xyz"
value_template: "{{ value_json.object.DOOR_OPEN_STATUS }}"
device:
identifiers: lorawan_door
manufacturer: Dragino
name: LDS02
I have also ttried:
value_template: >
{% if value_json.object.DOOR_OPEN_STATUS == "1.0" %} open
{% else %} closed
{% endif %}
This is unfortunately also not working.
What am i doing wrong?
How can i get the open/closed status from the 1.0 or 0.0 signal?
Thanks a lot
Florian