How can i get this in a Tile?

I would like to add the hight of the brook on the below link to a tile and cannot get it working any help would be much appreciated

Clipstone Brook level at Clipstone Brook - GOV.UK (check-for-flooding.service.gov.uk)

Are you mainly looking for the value of the current water level? 0.152m

If so, you could probably do it with a Rule and a Variable. This gets into some intermediate level topics, so I’ll put some notes below. The main concept is to create a numeric variable in SharpTools and then use a rule to make an HTTP request to get the water level.

Result

It would result in a tile looking like this (optionally styled as you see fit):

image

And the rule will end up looking like this:

Steps

I’ll briefly note the steps here, but please let me know if you have any questions or need further clarification.

Create Variable

From your SharpTools Manage Resources page, make sure the Variables tab is selected and then scroll down to the bottom and tap Create Variable

Enter a variable name (eg. ClipstoneBrookLevel), select the Number type, set the initial value to 0, and tap Create.

Create Rule

Open the SharpTools Rule Manager and tap the green + button to create a new rule. Make sure to enter a name for the rule in the first field (eg. Clipstone Brook Refresh)

Triggers

Under the Triggers section tap the +Time TriggerTimer. Leave the default option of Everyday and tap the time pill-button and adjust to your desired trigger time (eg. the time at which you want the data to be refreshed). Save the timer.

Optionally, repeat the previous step to add additional Timer triggers. For example, I have mine refreshing in the morning and the evening.

Flow

Under the Flow section, tap the +ActionHTTP. Leave the default method of GET and copy-paste the following into the URL field:

https://environment.data.gov.uk/flood-monitoring/id/stations/E21987/measures

This step will make the request to the UK Environment API to get the data.

Next, we’ll add a step to copy the value from the result of the HTTP request into a SharpTools Variable.

Tap the orange Save button to save the HTTP action, then under the Flow section tap +ActionSet Variable. For the Target, select the variable we created in the steps above (eg. ClipstoneBrookLevel).

Under ‘Select Source’, choose ‘Variable’ and then tap the ‘Choose Variable’ input that appears. Select the Context Variables tab, then ResponseHTTPResponse Data. When prompted for the data key copy-paste the following:

items[0].latestReading.value

image

The result of the HTTP request includes a bunch of data, so this grabs the specific value we’re interested in and then copies it into our SharpTools variable.

You can now tap the green Save button at the bottom of the rule to save it.

Add to Dashboard

At this point, your rule is setup and will automatically query for the water level and update the SharpTools variable periodically. Now we can add the variable to a dashboard.

Open your desired SharpTools dashboard in edit mode. Tap the green + button to open the Add Items window, then expand the Variables section and select your variable (eg. ClipstoneBrookLevel).

image

Optionally, you can tap the ... in the top-right corner of the newly added variable tile and edit the settings. For example, you might want to adjust the label of the tile. And in my case, I also used the special $.runRule() syntax to run our newly created rule whenever the tile is tapped. That way you can tap on the tile to refresh the value. :slight_smile:

To use the $.runRule() syntax, change the Action of the tile to Open Hyperlink, then copy the last part of the URL for your rule (just the ID) and enter the hyperlink as:

$.runRule("YOUR-RULE-ID")

See the $.runRule() syntax post for a more detailed example.

2 Likes

Wow, thank you that’s perfect and just what I was after.

I’m having an issue with the click to run though and isn’t updating when I click the tile not sure why but everything else works flawlessly :smile:

Can you share a screenshot of the tile configuration for the hyperlink $.runRule() syntax?

If you configured it from an iPhone/iPad, one thing to keep a close eye on is that straight quotes are being used instead of curly ones:

“Bad”

"Good"
2 Likes

That was it thank you josh!

2 Likes