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

Add capability to subscribe to Hubitat variables #60

Closed
wants to merge 12 commits into from

Conversation

sdachen
Copy link

@sdachen sdachen commented May 20, 2023

This PR adds the following functionality to allow the user to subscribe to hub variables and write to InfluxDB.

  • Add new UI section: "Variables To Monitor" that allows users to select Boolean, Decimal, Number, DateTime, and String variables.
  • Add logic to subscribe to variables through the UI and handle the incoming events through handleVariableEvent.
  • Add encodeVariableEvent analogous to encodeDeviceEvent that encodes variable events and values into InfluxDB formats.
  • Add getVariableEventList analogous to softPoll, without the capability to check for changes. getVariableEventList will always do a hard poll for all variables tracked.

@aerickson
Copy link
Contributor

I get an error when I try to run this. I haven't set up any variables to monitor yet... perhaps that the reason.

[app:528](http://hubitat.condo/logs#)2023-10-13 04:14:28.718 PM[error](http://hubitat.condo/logs#)java.lang.NullPointerException: Cannot execute null+null on line 414 (method updated)

It seems to be this block:

    // Subscribe to variables
    (booleanVariables + numberVariables + decimalVariables + stringVariables + datetimeVariables).each { name ->
        subscribe(location, "variable:" + name, handleVariableEvent, ["filterEvents": filterEvents])
        logger("Subscribing to variable ${name}", logInfo)
    }

I'm running from https://github.com/aerickson/InfluxDB-Logger/tree/INTEGRATION-snapshot1 (both #60 and #61 are merged in).

@dennypage
Copy link
Collaborator

dennypage commented Oct 14, 2023

@aerickson As it sits, this PR isn't being merged. Please run from the production version.

@dennypage
Copy link
Collaborator

dennypage commented Oct 27, 2023

@sdachen Thank you for your PR. I like the idea of adding the ability to publish hub variables to InfluxDB. After looking at the code, I thought that the implementation approach could be a bit simpler, and variable registration / rename handling was missing. In the end, it was easier to re-implement the feature rather than suggesting changes to the PR. I hope you don’t mind.

I am still in testing, but have created PR #69 that you can review. Please have a look and let me know what you think. Note that the output is not completely compatible with the previous PR. In particular:

  • For decimal variables it uses measurement ‘bigdecimalVariable’ rather than ‘decimalVariable’. This is because the bigdecimal is the type name used by Hubitat.
  • For boolean variables the InfluxDB type Boolean is used rather than Integer. The reason that Integer is used for Boolean values in device records is for backward compatibility with versions from long ago. Variables are new, so there is no requirement for them to use Integers to represent Booleans.
  • Datetime variables are not supported. It does not appear that there is any rational way to normalize these.

The changes look like a lot more than they are because I unrolled a bunch of input statements, which you can ignore. There is also a small additional feature which is the ability to publish the queue length as a variable.

@sdachen
Copy link
Author

sdachen commented Oct 27, 2023

@dennypage thanks for the detailed feedback and response - still new to developing on Hubitat and Influx so the feedback is appreciated. Please feel free to re-implement anything as you see fit. :) I'll review your PR and hopefully the community can start using the update!

@dennypage dennypage closed this Oct 29, 2023
@dennypage
Copy link
Collaborator

Version 3.3.0 is released

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

Successfully merging this pull request may close these issues.

None yet

3 participants