State information in a device driver code

So I need to make small modifications to a Hubuino driver code.
I have a water meter (using a hall effect sensor on my water meter) but it shows counts of 1 or 2 which I think are noise and I want to filter that out.
So I made a change so that it would ignore 1 or 2 and log numbers higher than that.
On the next poll, if its 0,1,2 I need to change the state to 0 ....to do that I need to know past state.
I read up on state variables and did the below.... the state variable doesn't show up under the device. I'm looking for any advice.... thx

Try = instead of == on line 59. If you aren't familiar with Groovy, it uses the C-family convention of = for assignment and == for comparison.

3 Likes

Thanks for catching that ...I thought I had fixed that....
After a little more reading i found when the initialize function and update function get run.
Got everything working thanks again.

state questions

  1. does the Hubitat limit how many state variables will be shown? I added several more but they will not show and i update preferences which should run update() See ones in yellow
    image
    image
  2. I no longer have a state variable called date but it still shows up..why is that ?
    Thanks
    Tim

You have to refresh the browser window in order to see state updates. They don't update automatically like attributes do.

You can use state.remove() like the demos here, and state.clear() of you just want to nuke things for a clean slate. EDIT: although, saving preferences does refresh the page. My guess is that the accessing the data for the page display is racing the actual data update. What happens if you refresh the page again?