Help with logic on calling a JSON with substitution variables

My whole house audio system runs on Nuvo and I have a script running in homeseer that provides all of the control. I can access the script through JSON with various commands, I have provided an example below that switches zone 7 to source 2

…?action=setaudio&id=Z07CHASRC2

I am working on creating a dashboard that can be called to allow changing the zones, adjusting the volume, etc. I could create 12 dashboards - one for each zone - but I was thinking there would be a simpler way to create one dashboard and then specify which zone to act on.

Perhaps setting a variable with the zone number so when the dashboard loads it knows which zone it is acting on and then can call the JSON with zone substituted.

I have a similar need to control my sprinkler system.

Any thoughts / ideas would be great. Thanks.

That would be the first approach that comes to my mind as well. Sounds like a cool project! Is there something particular you have a question about?

Many questions.

First - when calling this dashboard how do I store the Zone number in the variable?

Once in the dashboard, how do I substitute the Zone number in the variable into the hyperlink?

So I call dashboard Select_Zone and put the value 1 in Active_Zone variable.

Then in the dashboard when I click on any of the channel buttons, it calls the hyperlink with the value of Active_Zone substituted so the hyperlink switches the channel for the specific zone?

Thanks.

Assuming the URL you mentioned is accessible from an internet facing endpoint, you could use the HTTP Actions in rules. You can tap the +VARIABLE button to insert a variable into your string, so you could use it to dynamically set a parameter if you wanted.

I’m not familiar with the intricacies of your URL parameters, but something like the following where $inputDemo = 07 and $myText = SRC2

You have a few options with how you store the data in the variable. You could just add the raw variable to your dashboard and manually change the input as needed (eg. tap on the variable tile and type with your keyboard).

Alternatively, you could create individual tiles that act like selections for each of your different variable values. You could do this with individual rules that each just set the variable value, but I think this is a good use case for $.runRule() Rule Parameters.

Depending on your setup, you could use any Hyperlink enabled tile – for example, an actual Hyperlink Tile or Media Tiles showing images for your various sources so it’s a bit more visual.

$.runRule("ZoneSetterRuleId", {"zone": "07"})
$.runRule("SourceSetterRuleId", {"source": "SRC2"})

You can then use those parameters in your rule just like the HTTP Triggers (context → event → http): How to trigger SharpTools rules using HTTP - SharpTools Knowledge Base

In the examples above, I’m using two separate rules dedicated to just receiving the event context variable and storing that into your dedicated variables for this purpose. Again, you can adapt do your needs as you see fit.

I figured you might have different ‘actions’ on your dashboard like setting the playback source, changing the volume, etc, but you could certainly have the rule react directly to one of those inputs changing as well.

I would also add that if you have a bit of HTML + JavaScript skills, you could also do this using a Custom Tile. That would give you a lot more control over how the UI looks, but is more of a developer focused feature.

@josh I finally got around to working on this. Got sidelined by an unraid build.

I have created a rule as follows:

and then I want to call it from a tile on the dashboard so I tried using this:

$.runRule(“RULEID”, {“zone”: 1}, {“source”: 1})

I received the command on the host side but missing the substitution variables - so it looked like this: Z0CHASRC instead of Z01CHASRC1.

I read through the links that you sent but can’t quite figure this out? Thanks.

Two things to double check:

  1. The parameters should be in a single object containing all the parameters:
    $.runRule("RULEID", {"zone": 1, "source": 1})
    
  2. Make sure you’re using straight quotes, not curly quotes:
    Good: " " Bad:

Thanks, got that working.

Next question. My plan is to call a modal window with 6 buttons on it, one for each source (1 - 6) available. Ideally I would like to create one version of this dashboard and then set a variable when I call it with a number from 1 to 12 representing the zones. I am using a tile with a virtual variable to call the dashboard. This virtual variable contains the number the source currently playing.

image

Then when on this screen I tap one of the 6 source buttons and it sends the value of the variable representing the zone, which is dynamic based on how this dashboard was called, and the number of the source.

Of course I could create 12 dashboards but looking for a cleaner way to do this.

Scratching my head trying to figure out how to do this?

You could create a variable tile in the dashboard that is opened and use that to change which zone is being controlled. There’s not a way to pass a variable to a dashboard when opening it though. From a UX perspective, you may prefer to have different tiles on the dashboard to selecting the Zone you want to use rather than bringing up the default input modal where you have to edit the variable with a keyboard.

With the new Dashboard Overlay feature in beta, you could even create a dashboard dedicated to selecting the zone and have that pop-up in an overlay like a quick input selector.

Edit: You also have the Super Tile available to you if you want a custom layout for the zones/channels.

Edit 2: Visual mockup of a dashboard overlay approach…