Local expressions not evaluated in rules (MQTTController based entities)
-
Some background
I have MQTTController based entities that I want to use in time calculations in my rules. These entities represent two separate time ranges, one for the weekdays and the other for the weekends. In this particular example they are used to control my doorbell activity (whether it's enabled or disabled).
MQTT message which is used to update the entities. NOTE: time is in 24h format
{ "data": { "weekdays": { "enable": "09:28", "disable": "20:00" }, "weekends": { "enable": "09:00", "disable": "21:00" } } }
Entity definitions (here's only the definition for the weekdays for brevity)
doorbell-weekdays-enable: name: 'Ovikello päälle (arkisin)' topic: 'doorbell/settings' capabilities: - string_sensor primary_attribute: string_sensor.value events: "%topic%": "string_sensor.value": json_payload: true expr: "payload.data.weekdays.enable" doorbell-weekdays-disable: name: 'Ovikello pois päältä (arkisin)' topic: 'doorbell/settings' capabilities: - string_sensor primary_attribute: string_sensor.value events: "%topic%": "string_sensor.value": json_payload: true expr: "payload.data.weekdays.disable"
I have verified that the entities are populated correctly and the values are working in local expressions.
The entity (only the range start for brevity):
And the local expression within the rule:
weekdays_enabled = (time() >= time(getEntity( "mqtt>doorbell-weekdays-enable" ).attributes.string_sensor.value )) && (time() <= time(getEntity( "mqtt>doorbell-weekdays-disable" ).attributes.string_sensor.value ))
The problem
Local expression doesn't seem to evaluate to true even if the current time gets within the range. But if the related entities are updated, then the expression is evaluated and the rule is triggered.As seen from the screenshots, the current time is 09:28:12 and the start time in corresponding entity is set to 09:28. But still the rule is not triggered. However, if I update the entity e.g. to 09:27, the local expression will get evaluated and the rule is triggered.
My understanding is that the local expression is working correctly but since it's not evaluated, it will not trigger the rule.
Is this a bug or have I misunderstood something? If so, how should I implement this kind of functionality?
br,
mgvraReactor (Multi-hub) latest-23078-d592d400 + MQTTController [0.1.23010]
-
Conditions are not continuously evaluated, they are evaluated when a related object changes. The entity you are testing has set a value that doesn't change for a while after (once a day?). Just because there is a time component to the expressions and conditions doesn't mean that Reactor will test them continuously for time, or understand what your intent is and somehow turn that into a magic trigger for the right time.
Create a NUL group in your rule, and put an Interval condition in it with a one-minute interval. This will cause the rule to be re-evaluated every minute, which will cause your local expressions to be re-evaluated and then the updated values to be seen in the conditions.
Edit: great post, by the way. I'm going to use this as an example of describing the problem well and showing the work. Thank you!
-
Thanks for your quick reply!
With added NUL group and interval it seems to be working just fine.Well don't know about great post, just asking 'stupid' questions and hoping to learn something along the way.
But it's nice if it can be used as an example of how tackle that kind of problem.br,
mgvra -
T toggledbits locked this topic on