NEWS
State value
-
Hi, guys.
I'm trying to develop a new adapter and a couple of questions appears. Please help me with understanding:
1. After calling "adapter.setState(name, value, false)" in my code, MQTT itself performs ACK = TRUE after short time. Is it a correct behavior? I mean It is not necessary to reset ACK to TRUE after command processing in MY code?
2. Imagine the State Value was 0 (or even was empty). I set a value to 0 by calling "adapter.setState(name, 0, false)" or even through the web interface. In this case the adapter ACK becomes FALSE (and appears as RED in the web interface) and MQTT does not revert it to TRUE. Is this behavior correct?
Thank you
-
Hi, guys.
I'm trying to develop a new adapter and a couple of questions appears. Please help me with understanding: `
Hi and welcome to the developers
1. After calling "adapter.setState(name, value, false)" in my code, MQTT itself performs ACK = TRUE after short time. Is it a correct behavior? I mean It is not necessary to reset ACK to TRUE after command processing in MY code? `
Yes. Your code should only react on State-Changes from your own adapter with "ack=false" becaus ethese are the "commands" in ioBroker. After the command got proessed by the adapter, the adapter should update the state values to the "current value after processing the command" with ack=true.
In the end when your adapter writes info into own states they all should be "final" and so written with "ack=true".
Does this help?
2. Imagine the State Value was 0 (or even was empty). I set a value to 0 by calling "adapter.setState(name, 0, false)" or even through the web interface. In this case the adapter ACK becomes FALSE (and appears as RED in the web interface) and MQTT does not revert it to TRUE. Is this behavior correct? `
Depends on the use case.If you have adapter own state ids that are only used to trigger an action and so itself do not have a "state" (but maybe change other states) then it is ok because the command with ack=false will trigger the "trigger",which does an action.
MQTT may not be really the best example nbecause it is a communication bridge (as I understand it), so it may be that there are some cases where the ideal way is not implemented …
If you have real examples for your adapter it may help to give better ideas
Ingo
-
Hi, apollon77!
Let's clarify the first point at the beginning
"After the command got processed by the adapter, the adapter should update the state values to the "current value after processing the command" with ack=true."
Is it the my task?
Only I know when my command was processed and completed… Ideally, after I processed a command, I should resend to ioBroker engine a command ACK=TRUE. But instead of this, the MQTT background does it without my actions. Probably, I still didn't perform a command, but my setting a value becomes ACK=TRUE by itself. It worries me
-
I only talked about states from your own adapter that you write!! Please tell more about the mqtt topics … because mqtt is an own adapter and handles all own states like mqtt.0.statenane by its own. So yes for such a State the mqtt adapter is „responsible“ to set ack=true.
For all states of your adapter (e.g. singib.0.mystate ) you need to do.
-
I'm sorry for delay..
I'm trying to develop an adapter for Blynk.cc - nice mobile UI (as I use it). The current implementation is there: https://github.com/Go00oglin/ioBroker.blynk
After I understand that there is a change in UI on mobile device, I modify a value of state in the adapter (https://github.com/Go00oglin/ioBroker.b … er/main.js - lines 131 an d 136):
adapter.setState(stateName, newValue, false);
there are no any code in my adapter to revert ACK to true.
But my log notifies me:
blynk.0 2018-02-01 07:56:25.511 info stateChange blynk.0.V10 {"val":16,"ack":true,"ts":1517460985504,"q":0,"from":"system.adapter.mqtt.0","lc":1517460985504}
blynk.0 2018-02-01 07:56:25.484 info stateChange blynk.0.V10 {"val":"16","ack":false,"ts":1517460985478,"q":0,"from":"system.adapter.blynk.0","lc":1517460985478}
So, after I set a new value to State with ACK=FALSE, the system.adapter.mqtt.0 reverts it to TRUE mostly immediately itself.
-
And this is completely as intended. Your adapter tells the mqtt adapter that zu want to control this datapoint and that mqtt should set the neue value (ack=false). Mqtt reacts on this and after the change is done he sets the new value (in theory the value could be different) with ack=true to tell all others that there is a new officially set value.
So it works exactly like that.
-
Thank you, apollon77,
let me understand the idea.
1. I specified a new command (ack=false) with some value by calling adapter.setState(,false).
2. I thought, the my adapter should process this command in a part of my code and then should confirm this change by calling adapter.setState(,true).
Instead of this, the ioBroker body (ie mqtt) confirms setting of state on its own. So, the state changing is not a command, but just a value.
OK. but how to understand a documentation sentence "States can be written as commands or as statuses…. "?
sorry for my stupid questions
-
Thank you, apollon77,
let me understand the idea.
1. I specified a new command (ack=false) with some value by calling adapter.setState(,false).
2. I thought, the my adapter should process this command in a part of my code and then should confirm this change by calling adapter.setState(,true).
Instead of this, the ioBroker body (ie mqtt) confirms setting of state on its own. So, the state changing is not a command, but just a value.
OK. but how to understand a documentation sentence "States can be written as commands or as statuses…. "?
sorry for my stupid questions
`
As far as I understand your code: the all values for your virtual pins are updates of the states. Not the commands.You should send it with ack=true.
Only If you want to control states of other adapters (not yours) you should set the ack=false.
After this line https://github.com/Go00oglin/ioBroker.b … ain.js#L55 is executed, the ack in your adapter must be set to true. Or may be it will be done automatically because the adapter will get the update of the status here: https://github.com/Go00oglin/ioBroker.b ... in.js#L122
It took me sometime too to understand the concept of ack, but now it is self-evident.
You update your states always with ack=true,
Other adapters controls your states always with ack=false.
MQTT is not the body of ioBroker, it is just other adapter. And may be it has some logic on some client that acknowledges the state. ioBroker do not acknowledges the states automatically.