This is an automated archive made by the Lemmit Bot.
The original was posted on /r/tasker by /u/joaomgcd on 2024-02-02 12:41:33.
Today I received a request from a user that asked me to add a Power event to Tasker, in addition to the existing Power state that already exists. This made me realize that there’s actually no need for me to add events for states that already exist because you can easily create those events yourself!
Converting a State into an Event in 2 Easy Steps
- Create a State Variable for the state you want to convert
- Use the Variable Set or Variable Cleared events to react to the event of that state going on or off
Here’s an example (taken from the user mentioned above):
User’s Use Case:
In a situation where their mobile is wirelessly connected to the car’s audio system via Bluetooth & Android Auto Wireless, and being charged (either wirelessly or wired), a user wants to have warnings triggered when they turn their car off but forget to take their phone with them. The problem is that their Bluetooth connection remains active for a short time even after leaving the car.
The Problem
Currently, using the states Bluetooth Connected + Not Charging triggers a warn message prematurely - upon unlocking the car - before the phone even gets a chance to charge, because the condition of those states is true right away (Bluetooth is connected and the phone is not charging).
So, the user requested that I should add a new Not Charging event so that the the profile would only trigger when the phone is taken off charging, and not it first connects to Bluetooth.
The Solution
Create a State Variable for %Charging and then use that in the Variable Cleared event! :) Something like this:
Project: State To Event
Profiles
Profile: Set Charging Variable
State: Power [ Source:Any ]
Enter Task: Anon
A1: Variable Set [
Name: %Charging
To: 1
Structure Output (JSON, etc): On ]
Exit Task: Anon
A1: Variable Clear [
Name: %Charging ]
Profile: When Taken Off Charge And Connected to Bluetooth Remind Not To Forget Phone
Event: Variable Cleared [ Variable:%Charging User Variables Only:Off ]
State: BT Connected [ Name:* Address:* ]
Enter Task: Anon
A1: Say [
Text: Don't forget your phone!
Engine:Voice: default:default
Stream: 3
Pitch: 5
Speed: 5
Respect Audio Focus: On ]
In this example the %Charging variable is maintained separately and then you can use the setting and clearing of it as an event in any of your profiles!
Hope this helps someone out! 😎