Local Files in Rule 4.0

Hubitat Elevation Release 2.2.1 includes a new hub facility to support local files stored on the hub. These files can be created and managed in the hub web interface, and are also supported in Rule 4.0.

In Rule 4.0 local files are very similar to local variables of type String. There is a new action in the Set Mode or Variable section called Write Local File. This can be used to write a string to a local file. If the file does not already exist, it is created. If it does already exist, it is overwritten. There is also an action to append to a local file, that adds to the end of an existing file.

Note: Local file names may only contain these characters: A..Z, a..z, 0..9, - and _. Periods are also allowed but not as first character of file name.

In any context in Rule 4.0 where a String variable could be used with %variable-name%, a local file can be used by using %/local/filename%. Thus, the various actions that set a String variable by manipulating a string can manipulate the contents of a local file to set a String variable. The contents of a local file can be used in all other contexts where a String variable could be used as well.

A second way to create a local file in Rule 4.0 is to create a local variable whose name begins with /local/. When this is done, a local file is created with the name that follows /local/. This local file can be used in any context where a String local variable can be used, with one exception: A local variable that represents a local file cannot have a Connector. Deleting a local variable that represents a local file, deletes the local file. There is also an action to delete a local file.

It is important to note that there is a single file space for all local files on a hub. So if two rules "create" a local file of the same name either by Write Local File or be creating a local variable whose name begins with /local/, these would be referencing a single file of that name. It is possible for rules to pass information to each other by referencing the same local file, but care should obviously be taken as to which rules write to a given file.

Local files can be accessed on the LAN at [hub-ip]/local/fileName.

14 Likes

Is there any concern about storage space?

There is 1GB available. If you use it all up, an error would be thrown. This is a beta release of this feature. We'll figure out how people are using it. So, it's pretty basic.

Would you consider creating interfaces to write and read local files from custom apps and drivers?

2 Likes

Not until we understand better what is going on. There are lots of potential problems with opening file access on the hub. This is going to take some time to get scoped out and understood.

3 Likes

Can we host images and use them in dashboards? Audio clips for announcements?

5 Likes

How do you access the file manager? Are we able to upload files locally?

Given that it uses strings, probably not. There are no overt conversions going on, but I doubt you'll be able to get a binary value in and back out successfully. Give it a shot and let us know what you discover.

See below: Local Files in Rule 4.0

On the Settings page there is a tile for File Manager. You can upload a file from your computer there. All of the files in /local/ are there.

3 Likes

I’m still trying to understand.

If I upload a couple mp3 files are these accessible in rule machine ?

Can perhaps you list a couple use cases how we could use local storage.

Yes, as a string. But I don't think there's anyway to "play" a string.

We are hoping you guys come up with cool use cases. That's why this is beta. One use that I played with, that gets talked about frequently, is the creation of logs that can later be pulled out to your computer. RM could log just about anything by appending to a file, complete with time stamp. There are of course other ways to do this as well.

4 Likes

When I first saw this new feature. my immediate thought was to log Node-Red logs and when RM added support RW access, insert those logs into HE native log stream..
Thx

Is there anyway in groovy to call these files?

1 Like

Not yet. I think this is a try something small first, and expand use later if it goes ok thing. Patience.

5 Likes

Yes you can upload image files and other files (css for instance) using file manager in settings and use the local file url for dashboards

11 Likes

@thomas.c.howard this may come in handy for your apps!

1 Like

Just to clarify for everyone, yes, but it is LOCAL, so it won't work for cloud dashboards

3 Likes

No upload button or anything on mine...

A bunch of people experienced this during the beta. All I can say is I reloaded the page 4-5 tiems and then it worked and hasn't done this since. Since it's still a beta feature, I'm sure they're still working on it!

2 Likes

Would be a neat feature if we could specify a picture for local access and a different url for cloud access in the dashboard.

2 Likes