Update device only when value changes?

Question for seasoned plug-in developers:

If you’re polling a serial device in a plug-in is it best to check in Lua if the value has changed and only update the device if it has, or update the device regardless after every poll?

Or doesn’t it matter?

There’s effectively a “repeat” flag on each State Variable that’ll determine whether setting the “same” value causes change-events to fire or not.

There are cases where this is important (like SecuritySensor1) so you might choose to test-then-set in those cases.

For the most part it really doesn’t matter though… unless you particularly want to be cautious on write-cycles (since these can cause the data to be marked as dirty, etc, even if events don’t fire)

Most of my stuff I just “set”, even if it already has that value. SecuritySensor1 stuff I tend to test-then-set to minimize the likelihood of dup notifications.

That said, if I were polling often I’d consider using test-then-set since, eventually, these “changes” need to be written out to [flash] disk.

Thanks guessed - it was indeed the flash disk writing issue I was thinking about. The plug-in to which I refer is for a security panel so frequent polling is necessary. My code tests before setting, but I’d been wondering if it was worth the effort. I’ll leave it in. :slight_smile: