arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
466 stars 104 forks source link

MotionSensor please help #635

Closed iondarie closed 10 months ago

iondarie commented 1 year ago

Hello,

I have a Zigbee motion sensor that publishes to mqtt the following:

{"battery":100,"battery_low":false,"linkquality":52,"occupancy":false,"tamper":false,"voltage":3200}

I am trying to make it work on homebridge with the following code:

        {
            "accessory": "mqttthing",
            "type": "motionSensor",
            "name": "Magazie",
            "url": "mqtt://192.168.***.***:1883",
            "username": "*********",
            "password": "*********",
            "topics": {
                "getMotionDetected": {
                    "topic": "zigbee2mqtt/magazie",
                    "apply": "return parseFloat(JSON.parse(message). occupancy);"
                }
            },
            "integerValue": false,
            "onValue": "true",
            "offValue": "false"
        }

It will not work, it refuses to update the sensor. Please help.

Thank you,

arachnetech commented 1 year ago

I don't think you need the parseFloat there, because true and false are Booleans not floating-point numbers.

Since the on and off values are strings, you might need something like: "apply": "return JSON.parse(message).occupancy + '';"

iondarie commented 1 year ago

THANK YOU!!!! all works perfect now!