tobof / openhab-addons

The next-generation open Home Automation Bus (openHAB)
Eclipse Public License 2.0
39 stars 30 forks source link

Update issues with CustomSensor #69

Open FredericMa opened 7 years ago

FredericMa commented 7 years ago

Hi,

I'm using MySensors to keep track of my power consumption and therefore I'm also using a CustomSensor to store the pulse count of all sensors (Water, Gas and Power). All my sensors are connected to the gateway (issue that has been solved yesterday). I'm using the refactored binding which was released yesterday.

Config of the CustomSensor: image

I noticed that in both directions the pulse counters are not updated. So, to be more precise:

All channels are linked corrrectly. I only see this issue with the CustomSensor. The flowmeter and power things are functioning correctly and are updating it's values correctly (only receive from gateway, nothing is sent from these things).

If I gave a vague description, let me know what I need to clarify more!

Thanks!

Greetings, Frederic

andreacioni commented 7 years ago

Hi @FredericMa,

  1. What REST API have you used to change value on the item? POST:/items/{itemname} or PUT:/items/{itemname}/state ? The first one should work(in rules is known as sendCommand), the second one (in rules is known as postUpdate) is not actually implemented by the binding. I don't know if this could be considered an issue or is just a @Tim choice. We have to wait his opinion.

  2. For the second point, as I see in the log, channel is updated correctly and so I think it is just a visualization issue. Have you tried to see the behaviour of that item in a sitemap instead of Control panel inside PaperUI?

FredericMa commented 7 years ago

Hi @andreacioni,

  1. I used the PUT instead of the POST so indeed, that could explain why it wasn't updated correctly in the binding. But from another point of view. After a restart of OpenHAB the values should be restored by persistence and it looks like that also after a restart the values are also not restored correctly.

  2. Also in my sitemap, the values are visualised as 1000, the same as in the PaperUI.

andreacioni commented 7 years ago
  1. I agree with you, I encountered this problem also in my environment. I'm looking for a solution but, online, I found solution like this:

So I'm asking myself if a binding can restore the state that was saved through persistence services. Do you have any experience with another binding that restore the states of its things? What is your opinion @tobof ?

  1. I've tested update of that channel (VAR3) also in my environment and everything goes well. I've no idea about what is going on. Could you attach a file with a more detailed log?
FredericMa commented 7 years ago

Hi @andreacioni,

First of all, my appologies for the HUGE delay in my reply but I've been very busy the last few months so I couldn't invest any time anymore in my mysensors setup. Last week I've found time to pick things up again.

So what did I do: Instead of using the Custom Sensor I've switched over to the WaterMeter which contains a VAR1 variable to store the pulse counter and this seems to work correctly except for the restore at startup. When attaching the pulse counter that was previously connected to the CustomSensor to the WaterMeter I also needed to change the datatype of the item to Number whereas it was String before when it was linked to the CustomSensor. Probably this caused the issue of only visualising the state in the paper UI but not reporting it back to the gataway on request or updating it in the UI after receiving the pulse count from the gateway.

Like I mentioned above, the restore at startup is not working. I see that the value is restored in the UI but I think it doesn't propagate to a lower level in order for being reported back to the gateway upon request. This is ONLY when restarting OpenHAB. To fix this I update the pulsecount again via the REST api of OpenHAB. After doing this the gateway receives the correct pulsecount upon request. The message I see after a restart is the same as mentioned in earlier posts: Request received, but variable state is not yet define My guess is that the state is restored before the binding reconnects to the gateway because I also have seen this message in the logs: 2017-06-07 18:33:56.375 [WARN ] [rs.internal.gateway.MySensorsGateway] - Could not set value to node 0 if not reachable

Is this useful information?

Again, sorry for the big silence from my side!

Greetings, Frederic

FredericMa commented 7 years ago

@tobof : Do you have any idea what could be wrong? Thanks!

Greetings, Frederic

tobof commented 7 years ago

@FredericMa : Sadly, I've not yet found a workaround. It first came up two years ago: https://groups.google.com/forum/#!msg/openhab2/QbmaSwC59l0/NEJDfNRjAgAJ

The pulse count is stored (and restored through persistence) in the item(s). In the binding we're only dealing with the thing(s), we have no access to the items. To be able to answer requests (and for other useful things) we store the status additionally in the binding (runtime only).

I see two possible ways to workaround this:

1) Implement a persistance for the things of the binding itself. Won't be that hard I suppose, but saving the same value two times does not sound beautiful.

2) You create a rule in OH2 that is executed on startup that gets the value of the item and sends it via command (to itself). This will result in a mysensors message that nobody is waiting for, but also will store the current state in the binding and therefore a request could be answered. Maybe we should use handleUpdate() for that.

What do you think?

FredericMa commented 7 years ago

Hi @tobof

I checked the thread you've put in your comment. My knowledge about how bindings are implemented and how the communication between items and things works is very low. I should spend some time to figure this all out.

Probably I'm missing something but the first question that comes up in my mind is: Why is the state of a channel known by the binding after doing a sendCommand via the REST api and not at startup by the use of restoreOnStartup so it is restored by persistence? Is the restore on startup a total different mechanism? I would think this also just acts like a postUpdate or sendCommand?

Nevertheless, thanks for your suggestions. It is a trade off between the two options. Both have an advantage and disadvantage.

  1. The advantage is that everything is transparent for the end user and they don't see the "ugly thing" behind it. The disadvantage of course is that we need to store the same value twice like you mentioned.

  2. The advantage is that we don't have the double saving of the same value but the disadvantage is that people need to be aware of the fact that they need to implement a rule if they want to make proper use of the restoreOnStartup functionality.

If I need to make a choice then I would go for option one since it is the easiest to use for the end use.

Thanks a lot!

Greetings, Frederic