-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mqtt] Treat incoming empty string as NULL for most types #16307
Conversation
Empty strings are often received when deleting retained topics when a device goes offline, or as the result of a transformation that is missing a value (such as a "scene" event from zwave-js-ui, which sends JSON with a timestamp and the scene value, then immediately sends a value to the topic with only a timestamp). For string channels, add a configuration value to allow setting a specific string for treating as UNDEF, since empty string can make sense for that type. Signed-off-by: Cody Cutrer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this enhancement.
Just a question: Are you sure that UNDEF is the right state here and not maybe NULL?
UNDEF is meant for ambiguous situations, when there actually IS a real state out there, we just do not know how to represent it in the item. NULL means that there isn't any state at all.
...penhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/Value.java
Outdated
Show resolved
Hide resolved
...g.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/RollershutterValue.java
Outdated
Show resolved
Hide resolved
....binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/NumberValue.java
Outdated
Show resolved
Hide resolved
No I'm not sure at all. I'm never quite clear on which of whose is which. The intended purpose here is "we know that the item does not currently have a state" not "we don't know what the state is." I thought UNDEF was what I wanted, since NULL is what items start out as when first created or on boot, before persistence has restored them (and thus we don't know what their state is, or if we even have a state). |
Well, the question is how we want treat the incoming value. If we say that the current state of the item is probably right and we simply want to ignore the incoming empty string, then UNDEF is probably indeed the right option. If the empty string means that a topic does not exist anymore and there is no representation "in the outside world" anymore, NULL would be better. |
Okay, I think we want use NULL then. UNDEF is used for NaN, which does match your description, and this is for either "the device is gone, so no longer has a state" or "there is no state." Either of which is a definitive representation. |
Background: I have been running Zwave-JS-UI (zwave2mqtt) using generic MQTT things because of issues with the HA configs (i.e #15145). As noted above, HA scenes configs have momentary values, but revert to empty. I addressed (no WARN messages) with the empty Scene topic problem in the generic MQTT by using a string channel, only getting the "value" and using MAP (=OFF). I recently set up a test environment mirroring one production instance using the HA configs. The HA Scene configs are pulled into OH as a number channel; And the WARN sequence (just 1 example). I have 26 scene channels (not all used).
Anyway I was going to create an issue, but saw this PR and wanted to ask if this code was going to fix the Scene problem? If not, is there a way to change the HA Scene config from Number to String in OH? Despite all the complexity, all the Scenes contain "91" as that is the Zwave command class enum for central_scene. |
@apella12 : yes, this will fix that error in the logs. And is one of several reasons I wrote this PR. I also use zwave-js-ui. |
since these are for definitive "this channel no longer has a value", not "this channel has a value we simply can't represent" Signed-off-by: Cody Cutrer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
Hi ErikDB87, Cheers, |
Heh, yes, I was very aware the Homie convention forbids empty payloads (presumably because that's how you "delete" retained topics in MQTT). But given their language, one should never encounter an empty payload, and thus doesn't specify how one should handle it if it does happen - it's simply error handling. For example, it does not say "a client should retain the prior value when an empty string is received." I was not aware of that discussion, or even the existence of an upcoming Homie 5, so thank you for that link. I stopped looking at the spec when it had not changed for years, except for some minor changes that they didn't actually change the version number for. I do agree with you on the alerts topic though- the spec is so vague as to the contents of its payloads that it's essentially useless. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
) * [mqtt] Treat incoming empty string as NULL for most types Empty strings are often received when deleting retained topics when a device goes offline, or as the result of a transformation that is missing a value (such as a "scene" event from zwave-js-ui, which sends JSON with a timestamp and the scene value, then immediately sends a value to the topic with only a timestamp). For string channels, add a configuration value to allow setting a specific string for treating as NULL, since empty string can make sense for that type. Signed-off-by: Cody Cutrer <[email protected]> Signed-off-by: Jørgen Austvik <[email protected]>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/ignoring-empty-mqtt-payload/154554/9 |
Since openhab#16307, the state could get set to NULL, not just UNDEF, and once it got in that state PercentageValue would throw an error every time it received any other message or command, effectively rendering the channel broken until openHAB restarted. Signed-off-by: Cody Cutrer <[email protected]>
Since openhab#16307, the state could get set to NULL, not just UNDEF, and once it got in that state PercentageValue would throw an error every time it received any other message or command, effectively rendering the channel broken until openHAB restarted. Signed-off-by: Cody Cutrer <[email protected]>
Since openhab#16307, everything except TextValue would treat an empty string as NULL. TextValue was excluded because empty string could be a valid value. Instead it had a config option added to match for a NULL value if you wanted. BUT, if a TextValue has specific valid states configured (such as from Homie or Home Assistant bindings), then empty string is no longer a valid value, and should receive the same treatment of setting the state to NULL when encountered. Signed-off-by: Cody Cutrer <[email protected]>
Since openhab#16307, everything except TextValue would treat an empty string as NULL. TextValue was excluded because empty string could be a valid value. Instead it had a config option added to match for a NULL value if you wanted. BUT, if a TextValue has specific valid states configured (such as from Homie or Home Assistant bindings), then empty string is no longer a valid value, and should receive the same treatment of setting the state to NULL when encountered. Signed-off-by: Cody Cutrer <[email protected]>
) * [mqtt] Treat incoming empty string as NULL for most types Empty strings are often received when deleting retained topics when a device goes offline, or as the result of a transformation that is missing a value (such as a "scene" event from zwave-js-ui, which sends JSON with a timestamp and the scene value, then immediately sends a value to the topic with only a timestamp). For string channels, add a configuration value to allow setting a specific string for treating as NULL, since empty string can make sense for that type. Signed-off-by: Cody Cutrer <[email protected]>
Empty strings are often received when deleting retained topics when a device goes offline, or as the result of a transformation that is missing a value (such as a "scene" event from zwave-js-ui, which sends JSON with a timestamp and the scene value, then immediately sends a value to the topic with only a timestamp).
For string channels, add a configuration value to allow setting a specific string for treating as NULL, since empty string can make sense for that type.