HTTP trigger support (Send battery % from Android device)

Here’s a working example for you:

Explanation

Starting with the SharpTools Rule, in the Triggers section we add an Event → HTTP Trigger and optionally define the parameter name battery within the HTTP Trigger in advance.

Then in the rule Flow, we add an Action → Set Variable where we select a target SharpTools variable to set the value to, then set the source as Variable → Context Variable → Event → HTTP Event → Parameters → Battery.

If you didn’t define the battery parameter in the HTTP Trigger, you can select the HTTP Event → Parameters → Custom Parameter option and type `battery here.


On the Tasker side, we’re using a Net → HTTP Request action with the GET method. Our URL is copied from the SharpTools HTTP Trigger and the Query Parameters are in the weird Tasker format:

Key:value

So for our case we want the system variable %BATT to come across in the battery parameter:

battery:%BATT
1 Like

You can use either. We support passing the parameters in via URL query parameters (for HTTP GET) or via the body as a JSON payload (for HTTP POST).

Just added a full example above. :slight_smile:

Amazing! Thank you Very much. When I try to replicate the sharptools variable I am asked to create a variable. When I try to create the variable $Batteryphone (text) it asks for a value ?

I created my variable as a Numeric type and you can either leave it empty or initialize it with a value (I used 0).

I have successfully created the tasker task but I am struggling with the sharptools variable setup.
If I create the variable as a text with 0, then when I try to add it to the rule (I guess as a manual input, right) I cannot add $context.eventparams.battery value . I can only input a value?

Can you please share screenshots of where you’re having difficulty? I would also refer to the explanation / description I added to the screenshots post.

I would also encourage a read through of the How to Trigger SharpTools Rules using HTTP article I linked above as it has examples, screenshots, and GIFs showing the concepts.

Please see attached screenshots. I have followed all steps but the tile looks strange.


I was looking at the logs and it’s seems no battery % is been sent? Pls see attachment!

This is my tasker profile.

Sorry about all the messages lol… I manage to get it right and now I get the % - see the logs. However the tile (I have added the rule as a tile, right) is still not displaying any data.

Lol this is a learning curve :rofl:. I have added the tile as the variable and now I can see the battery level. Any chance I could add the % ?

1 Like

Also, what is the best way for the tile to change colour once the device is plugged in? I was not able to find any customizations for that variable tile. Do i need to make a new one?
(Tasker will be sharing the trigger via HTTP).

@George_Vassilakis, have you setup in Tasker to send a HTTP request to update the variable accordingly when the device is plugged in? You can customize the tile style to show different color when a variable value is set to “plugged in” or whatever desired. However, the challenge is you will need a different variable for this because the variable tile can only display one value at a time. You can show either the battery level or the charge status in your variable since your variable is a TEXT variable, but not both in the same time. If you want to set both battery level and the charge status to the same variable, you will need to make sure the Tasker doesn’t send the batter level HTTP request when the device is plugged in so the charge status doesn’t get over written in the variable.

Thanks James. The battery variable is configured as a number not text in Sharptools. The way i have setup the current tile is - please below - based on the battery % vs colour.
Is there a way to add the logic for charging / not charging on the same tile? I understand that i need to setup a new variable from tasker - but would that need to be shown as a different tile ?

Also, how can i add the “%” on my tile. Many thanks for your support.

Yes, it would either need to be a separate tile or you could change the variable to a Text type and within Tasker conditionally choose whether you sent the battery level or the charging status.

I’ve noted the feedback as we’ve been considering a ‘Super Tile’ of sorts that would allow you to combine data from multiple Things or Variables. :slight_smile:

There’s not a configuration setting for it, but you could use Custom CSS if you don’t mind tinkering a bit.

.tile.variable-number .value::after {
    content: "%";
}

Note that the above snippet would add a % symbol to every numeric variable tile. There’s a community maintained CSS Wiki. You can also target custom css to specific ‘named styles’ if you only want this to apply to certain tiles.

Please note that any custom CSS snippets provided are not officially supported and may need to be adjusted with potential future changes to the SharpTools web app.

The super tile option looks amazing!

I am trying to target custom css to my specific tile but i think i am messing it up.

I have created a new style for my active theme called “battery” but i think i need some help to create the css - see below LOL. That is not working. Any help is much apricated!

.tile.–theme-style-battery{ tile.variable-number .value::after {
content: “%”;
}!important; }.

Try the following:

.tile.--theme-style-battery .value::after {
   content: "%";
}

Please note that any custom CSS snippets provided are not officially supported and may need to be adjusted with potential future changes to the SharpTools web app.

Hi Hosh, that didnt work :frowning: . See below my setup please.

I am editing the tile and have selected the battery100 style (that lives under battery theme, which is selected for the dashboard). The % is not visible.

Any thoughts?

[/quote]

The style is called battery100, but the css is targeting a style called battery

The CSS needs to target the exact style name. You can add multiple targets in a single CSS declaration too:

.tile.--theme-style-battery100 .value::after,
.tile.--theme-style-battery80 .value::after,
.tile.--theme-style-battery60 .value::after,
.tile.--theme-style-battery40 .value::after,
.tile.--theme-style-battery20 .value::after {
   content: "%";
}

The names of each comma separated line would need to be updated according to the styles you define. :slight_smile:

Got it! :slight_smile: I think i have now understood how this works! Many thanks!

2 Likes