Skip to content
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 retain #2

Open
firefigther0575 opened this issue May 29, 2023 · 5 comments
Open

Mqtt retain #2

firefigther0575 opened this issue May 29, 2023 · 5 comments

Comments

@firefigther0575
Copy link

using it for a week now and it works great!!! stable!
but having some issue with the retain properties of mqtt sometimes it doesnt update the sensor and it retains the previous message.

what are youre thoughts on that.

greets

@cyberjunky
Copy link
Owner

@firefigther0575 I'm not sure, do you have an example, logs to show what exactly is logged?

@bobskee
Copy link

bobskee commented Nov 25, 2023

Maybe it is not the same issue as @firefigther0575 is experiencing but I had something similar.
When I create automations that trigger on 'state or attribute changes' of a p2000_rtlsdr MQTT entity, it first gets triggered because it publishes its 'attributes', followed by another trigger because it publishes the 'state' of the entity [source].
If you include actions or conditions that use the 'state' value it uses the old value of 'state' because that value is not updated yet, but the automation gets triggered earlier than intended because of 'attribute' changes.

@cyberjunky
Copy link
Owner

@bobskee how did you workaround this, did you manage to change your automation? If so can you give an example for the documentation?

If you haven't got it working, I'm not sure if changing the code can fix this, I can switch the order and first do state and then attribute update, but either one is lagging. Need to look on how other add-ons do this.

@bobskee
Copy link

bobskee commented Jan 3, 2024

I am not proud of my workaround but in my case it fits my needs. My automations now only trigger on changes of the 'tts' attribute. Everything else is ignored and unused. Then the 'tts' value is checked against a locally cached value (using a input_text helper in HA) to verify it truely changed since the last time the state was updated. If true then continue the automation.

I am very curious how other addons handle those MQTT updates. P2000_rtlsdr is the only project I use where this is an issue (still very grateful for your work!)

@LiquidBlackNL
Copy link

Hi all,
I think I experience about the same thing. I tried making it visible via Node-Red. :)

Addon config example:

- id: 1001
  name: P2000 NR
  icon: mdi:message-bulleted
  capcode: "*001033216*,*001180000*"

This is a debug dump (from Node-Red) from the sensor.
You can see the new_state is a new message from another capcode on the same sensor.
You can see everything is updated expect the "state". The state remains the same as the previous message.

old_state:
image

new_state:
image

Hope it helps!
I think I can work around this myself by using the mqtt topic as a source in Node-Red instead of the sensor by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants