[SOLVED] Rule machine logic: I want to trigger "less than"

I have a presence sensor, LD2420 connected to an esp8266 running ESPHome. I get values from the sensor into Hubitat with help of the MQTT handler app. Works great.

The payload from the sensor is changing slightly all the time with a value around 770-790
If I walk nearby the sensor the value changes to under 500. I want to use this payload as a trigger but there is no "less than" option for my 'Custom attribute' in rule machine.

How can I make a trigger that works?

Regards,
/David

What driver are you using? It must be a custom driver, so a link to the code would be the most helpful.

In any case, even without looking at that, it seems this value is coming in as a string. Given you mentioned MQTT and this attribute is called "payload," I'm guessing a driver change won't do much here since any data type might come in, so it needs to be a string, then you can parse whatever you want out of that. To do that, you'll need to trigger on "changed," then create a local variable (or hub variable if you really have a use for it outside the rule) of type Number, then use the "Set Variable" action to set the value of that variable to this numeric string (that is a specific action you can choose).

Then, you can use an IF THEN in your actions to test whether that value is below 500 and do something in response -- or however it is that you want to handle this logic.

I don't know how familiar with RM you are, so that's the general idea. If you need more specific help, just ask!

2 Likes

Thanks. I will look in to the 'local variable' solution.
This is the driver I use to fetch the data from my MQTT broker. I use it for two other sensors and it works great.

https://raw.githubusercontent.com/parasaurolophus/hubitat-mqtt-connection/master/mqtt-connection-driver.groovy

That doesn't look like the driver for the device above (possibly a parent driver for the device?), but in any case, I suspect the explanation is as above. This isn't a Rule Machine issue since it does indeed offer those triggers for attributes/events of the appropriate (numeric) type, so this should work for drivers that need to do other things for some reason as this one likely does.

This must be the driver. Works together with the first one.
I will try the Local variable solution. :slight_smile:

https://raw.githubusercontent.com/parasaurolophus/hubitat-mqtt-connection/master/mqtt-handler-driver.groovy

1 Like

I don't know how your illuminace sensor works but the zooZ sensor I use, the driver can be adjusted to deliver updates based on elapsed time or changes in the light. What I did was to make a motion trigger with a required expresson. The expression evaluates the sensor's last reported light level and triggers based on that and there are no other lights on. I use it to turn on a light when there is motion and the room is dark.

1 Like

I solved it the quick and dirty way. Duplicated the driver and changed the line from STRING to NUMBER and from that on I got < and > to play with in Rule Machine. Thanks for your help!

// Payload of incoming message.
attribute "payload", "NUMBER"

1 Like