[RELEASE] Generic Attribute Storage Driver

I made another small utility driver today that includes some basic attributes and "set" commands to store values in these attributes. The driver currently allows for integers, floats, strings and dates. Am happy to expand later on once I look a bit more into other data types (booleans, times, maps, etc).

The intended use is to allow storage of a small amount of simple data through calls to commands on the device via something like Maker API, without the need for a specific device driver for each specific use case. Obviously there are probably a large number of uses for this, so thought it was worth sharing. Enjoy!!

Screenshot of Device Setup Page:

Code (remember to grab the RAW version... One day I'll set all my stuff up in HPM....):

https://github.com/sburke781/hubitat/blob/master/UtilityDrivers/GenericAttributeStorage_Driver.groovy

Simon

Change History:

Change History:

2021-03-07 Original Creation
2021-03-07 Added Refresh capability so that devices would appear in Maker API
2021-03-08 Change Refresh Capability to Actuator, which also allows for running custom commands

9 Likes

I have zero coding experience. Is this to allow say, tasker to send the value of a stored variable to hubitat, and have this logged as a value for one of this devices attributes?

(not sure if that's the correct terminology).

If so, would you mind giving an example of how to do so please?

/stupid.

1 Like

You're spot on in your description. I'll try and write up some notes after I have dinner. I took some notes on the Tasker thread we have been involved in recently for alarms, so you could look through some of those notes as a start.

1 Like

Some basic steps to setup a device with this driver and include it in Maker API are:

Installing the Driver

Access the link to the code from the first post in this thread, clicking on the RAW button to get the raw text displayed in the browser
Copy the driver code to the clipboard
Open the Drivers Code section of the HE Web UI
Click the New Driver in the top right of the screen (I think this may appear slightly different when no custom drivers have been installed)
Paste in the driver code text copied earlier and click Save

Setting up a Device

Go to the Devices page in the HE Web UI
Click the Create Virtual Device button
Enter a name and select the Generic Attribute Storage Driver in the Type drop-down
Click Save Device
The Device Edit page will be displayed
Note down the device id in the URL of this page (the last part of the URL)

Test the new device by entering a whole number in the setIntegerAttribute command button and clicking the button to store an integer. A new attribute will appear under the Current State section on the right hand side of the screen.

Setting Up Maker API

This is only required if Maker API has not been installed or a new install is desirable for any reason
Open the Apps page in the HE Web UI
Click the Add Built-In App button
Select Maker API from the list
Provide a name for the Maker API app instance if desirable
Select the new device created with the Generic Attribute Storage Driver
Adjust any other settings as required
Take a copy of the Send Command example URL from the last section of the app setup page
Click Done to complete the installation of Maker API

To test the install, paste the example sendCommand URL into a browser Address Bar, change the [Device Id] text to be the Device Id noted earlier, change the [Command] text to setIntegerAttribute, change the [Secondary value] text to a number, e.g. 30, now click the appropriate button in the browser to access the URL (or press Enter on the keyboard)
Some text will be displayed with various details about the device including values as they were before any changes were made by accessing this URL. Open the Device Edit page again for this device and review the Current States section and in particular the integerAttribute value, it should match the value passed in to the URL constructed above, e.g. 30.

At this point you now have the ability for external systems to store integer, float, string and date values by calling the maker API and providing the appropriate device id, command and parameter value. One example of an external system could be tasker using a HTTP request task.

In RM these attributes could be used in various ways, including loading their values into other variables for use in other parts of a rule.

I'll leave it at this for now, any more details or help people may need, happy to expand on this or for people to post their own uses of this driver.

Simon

2 Likes

This. Is. Awesome. :heart: :heart: :heart:

Thank you thank you thank you. I've been using a Virtual Omni Sensor to be able to pass string variables from one hub to another - this is much neater and cleaner and easier.

One suggestion: I've added capability "Actuator" so that the device can be used with "Run Custom Action" in RM.

2 Likes

@sburke781 Neat stuff. Going to look into it.

Also, with respect to my tasker alarm thread, after a little searching I found this device driver that creates a virtual device to act as a countdown.


I'm still testing it over large amounts of time, but so far it looks good. You enter a time in minutes, click on the start button and it starts counting down to zero.
Could your driver somehow be made to work with it?
1 Like

With a few modifications to the timer driver it would be possible I think. Probably need to add a command to set the time, then I expect we may be able to set it from a rule.

I'm about to start work so won't be able to look at it til later today. Nice find.

Thanks @jwjr. I noticed that as well, added the refresh capability to achieve this, but I think the actuator idea is probably neater.

1 Like

Small update to capability from Refresh to Actuator, thanks to @jwjr for suggesting this. Have added a change history section to the first post in this thread to show changes such as these.

2 Likes

Loving the progress on this. Many thanks.

Noticed that allowing webcore access allows me to set a date with time.

This however is the result. Not sure if this info is helpful to anyone.

Thanks @djh_wolf, glad to hear people are finding this useful.

I was a little surprised I couldn't easily find a way to store a date/time in an attribute, I need to look at this more, I'm sure I just haven't spent enough time on it. Most systems (I believe) would store dates and date/time values as numbers behind the scenes, then presenting them in the formats we are more familiar with when presented back to us. So I expect the number you are seeing is something like that, e.g. the number of minutes / seconds since a set point, usually 1970 or 1900, etc.

I'll see what I can do, but am open to anyone else playing around with this and offering a solution....

Thanks,
Simon

1 Like

@ sburke781, in a project I'm working on to store battery change dates, I figured out this code to get the current date/time as a string:

def str = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date())
1 Like

@sburke781 I don't know if this would be useful to anyone else, but could you add an option so that whenever it receives data from a device, it sends a reply to that device telling it that the data has been successfully received?

This would help account for any potential wifi hickups.
Tasker would send data and then wait for a reply. A received reply would tell tasker that everything worked ok. If no reply is received, then there may have been an issue, so tasker will resend it several more times, until it either succeeds, or it times out.

1 Like

@MMMmmmm,

Good idea, I definitely think that is worthwhile pursuing when using this driver / device in your example of Tasker, or any external system. I don't think this driver will be the place to implement this feature, given the ways driver can be used are so broad, not just with calls from Maker API. So we will need to look at where and how we should achieve the response. One thought, without having investigated if it would work might be an RM rule that is triggered by an attribute change and calls back to Tasker with a http call. A few things in that I can't be sure will work, so it needs more work (can you tell I'm on my lunch break at work :slightly_smiling_face: ).

Simon

Just wondering... is it possible to add more than one stringAttribute (etc)?

I'm thinking this may be a way to streamline another of my tasker projects. ;D

1 Like

I was thinking about it as I was writing the driver. There's a few options I need to mull over, but definitely possible.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.