DevSecOps
Well-Known Member
- First Name
- Todd
- Joined
- Sep 22, 2021
- Threads
- 69
- Messages
- 4,740
- Reaction score
- 11,500
- Location
- Sacramento, CA
- Vehicles
- '21 Audi SQ5 / '23 Rivian R1T / '23 M3P
- Occupation
- CISO
- Thread starter
- #1
Okay, so I've kept quiet on my little project over here regarding an Android Widget that I've been in the process of developing.
If you are looking for something that is easier check out this post here by @kennelh : https://www.macheforum.com/site/threads/android-widget-for-mach-e.13563/. I believe that the biggest difference is look/feel and the fact that my widget has buttons that command the car to do things just like within FP.
IMPORTANT: Due to the complexity of the widget it's not going to be available for everyone. I wanted something that was very functional and informative and to accomplish that I used a number of different things including listeners for event changes, pushing notifications from the listeners to the phone, the phone intercepting these events and then performing queries of the data which populates the widget. I also wanted something that I can style infinite ways and this gives me, and anyone else, that ability. Once setup you can customize it easily in the GUI to however you'd like.
So to go along with this there's a poll. I want to see if there's interest out there for some of the more technically inclined folks for me to publish a "how to" on this. Edit: guide was posted below.
ON TO THE WIDGET:
All of the data is in real time.
Unlocked vehicle, passenger window open, not charging, not on
Charger plugged in (not actively charging, frunk open, tailgate open, passenger door open, all windows closed.
Additional Images Here
Requirements:
If you already have HA with FP installed the total time to complete the below steps should be about 30-45 minutes. So it's not that hard since I've given all of the imports with the majority of the work.
Step #1:
Prerequisites -
Create a Helper in HA. Give it the name: "KWGT Refresh - Android MME Widget"
Create the following two automations in HA:
Add as many entities to the above code as you want to monitor for changes. When the states change for the above entities it will trigger a refresh on the phone. You can add as many or little as you want.
NOTE: The FordPass HA integration automatically subscribes to events from the mother ship and "should" be updated every time there's a vehicle change. If you want to force a refresh you can do this by triggering fordpass.refresh_status on a timed interval. By allowing HA to handle this the load on the phone is minimized. You can still trigger the message notification to the phone on the changed states as you wish, which won't change the refresh status on the phone (so long as you don't pick the refresh timestamp as the trigger). It should be noted that this command queries the vehicle to report. This means that battery is used. I am testing the impact of this right now, but use caution.
Below is a simple automation example that runs every 30 minutes:
WARNING: In testing with short intervals the vehicle is kept awake which causes LVB discharge. Use the above command/script with caution. It is not required for the widget.
Step #4:
First of all, go the the “Long-Lived Access Tokens” section at the bottom of the Profile page of your Home Assistant. This page can be accessed by clicking on your name, at the bottom of the main menu
Create a new token, and keep the token value somewhere for the next step. We are done with HA at this point.
In the VARS tab of Tasker, create 2 new variables:
Just click on the following links with your mobile device and follow the instructions
Step #5:
Import the following into Tasker. These are the refresh, start, stop and lock, unlock commands:
Once you have these in place you should be able to test the commands by running them. This will verify that all the previous steps have been done correctly. With the exception of the intercept of the "Re" message, which we will get to later.
Step #6:
Prerequisite - KWGT must be installed on your phone already
Import the below into Tasker. There's 58 tasks in here that are used to query HA and push those results into KWGT. There's also a couple tasks that normalize date and times for active charging calculations.
After the above is imported go to Profiles and create a new profile.
Step #7:
For anyone who just blindly followed my directions here's what we did in review:
You should be able to look around and see how I coded things to work. Anywhere you see a little calculator icon is where there's custom code controlling the behavior of that object. Most of the time this is in the colors and visibility of layers.
Buttons to control actionable events are created as layers. Thus, for example, if the vehicle is locked then display the locked icon with a button action of unlock. In this example the layer is only present if the conditions are met. This allows the button to be able to switch between lock and unlock since lock actions in HA don't have toggle properties. Same goes for remote start.
There's other areas where I changed words because the returned results are not so pretty. You can easily modify all of this as you wish.
For the battery gradient, it goes from green > 50%, Orange > 30% and Red below that. If you go into the color calculator you'll see the formula I used for that, you can change those ratios or colors as you wish.
Have fun!
To Do:
If you are looking for something that is easier check out this post here by @kennelh : https://www.macheforum.com/site/threads/android-widget-for-mach-e.13563/. I believe that the biggest difference is look/feel and the fact that my widget has buttons that command the car to do things just like within FP.
IMPORTANT: Due to the complexity of the widget it's not going to be available for everyone. I wanted something that was very functional and informative and to accomplish that I used a number of different things including listeners for event changes, pushing notifications from the listeners to the phone, the phone intercepting these events and then performing queries of the data which populates the widget. I also wanted something that I can style infinite ways and this gives me, and anyone else, that ability. Once setup you can customize it easily in the GUI to however you'd like.
So to go along with this there's a poll. I want to see if there's interest out there for some of the more technically inclined folks for me to publish a "how to" on this. Edit: guide was posted below.
ON TO THE WIDGET:
All of the data is in real time.
- If a door, window, trunk or frunk is open the app will alert as shown below in the area where said object is open.
- If the tire pressure falls below the limit the circles will turn red.
- When the car is turned on the power button changes to blue. This button also serves as a remote start.
- If the alarm is set, it turns green, of alarm is sounding it turns red.
- When doors are locked it turns red. This button also serves as a door lock/unlock button
- The FP Icon opens FordPass
- The ChargePoint Icon opens ChargePoint
- The charge button is grey for unplugged, white for plugged in, blue for charging.
- Touching the Mach-E logo will force a refresh of HA from Ford, which will in turn update the widget if changes are available.
Unlocked vehicle, passenger window open, not charging, not on
Charger plugged in (not actively charging, frunk open, tailgate open, passenger door open, all windows closed.
Additional Images Here
Requirements:
- HA - WAN accessible
- HACS w/FP (free)
- Android - Tasker (free)
- Android - AutoRemote - Part of Tasker AutoApps (free)
- Android - KWGT (free)
If you already have HA with FP installed the total time to complete the below steps should be about 30-45 minutes. So it's not that hard since I've given all of the imports with the majority of the work.
Step #1:
Prerequisites -
- Make sure that you have Home Assistant with a WAN accessible URL. Your phone will need to connect to HA.
- Make sure you have installed and setup FordPass in HA. (link)
- On your Android phone download Tasker and AutoApps-AutoRemote
- Open AutoRemote and go to the URL provided.
- Inside of the website type "Re" (without quotes) in the message box.
- A blue box will appear with a url to send the message directly. Copy this url.
- Open HA and edit the configuration.yaml file
- Past the following replacing the url with that of the coppied above:
Code:
rest_command:
autoremote_refresh:
url: "https://autoremotejoaomgcd.appspot.com/..............
- Restart HA
- Go back into AutoRemote and go to the settings (bottom left) and then alerts and disable the toast notifications otherwise every time there's an update pushed it will toast. If you want to leave it on for testing purposes feel free, but eventually you'll want to turn it off.
Create a Helper in HA. Give it the name: "KWGT Refresh - Android MME Widget"
Create the following two automations in HA:
YAML:
alias: KWGT MME Boolean
description: ''
trigger:
- platform: state
entity_id: >-
lock.fordpass_doorlock, sensor.fordpass_elveh,
sensor.fordpass_tirepressure
condition: []
action:
- service: input_boolean.toggle
target:
entity_id: input_boolean.kwgt_refresh_android_mme_widget
mode: single
YAML:
alias: KWGT MME Rest Command
description: ''
trigger:
- platform: state
entity_id: automation.kwgt_mme_boolean
condition: []
action:
- service: rest_command.autoremote_refresh
mode: parallel
max: 10
Below is a simple automation example that runs every 30 minutes:
YAML:
alias: 'Refresh FP * 5 '
description: ''
trigger:
- platform: time_pattern
minutes: /30
condition: []
action:
- service: fordpass.refresh_status
mode: single
Step #4:
First of all, go the the “Long-Lived Access Tokens” section at the bottom of the Profile page of your Home Assistant. This page can be accessed by clicking on your name, at the bottom of the main menu
Create a new token, and keep the token value somewhere for the next step. We are done with HA at this point.
In the VARS tab of Tasker, create 2 new variables:
- HA_ADDR is the address of your home-assistant instance
Add the port if there is one, and no trailing slash - HA_TOKEN is the token you created above
Just click on the following links with your mobile device and follow the instructions
Step #5:
Import the following into Tasker. These are the refresh, start, stop and lock, unlock commands:
Once you have these in place you should be able to test the commands by running them. This will verify that all the previous steps have been done correctly. With the exception of the intercept of the "Re" message, which we will get to later.
Step #6:
Prerequisite - KWGT must be installed on your phone already
Import the below into Tasker. There's 58 tasks in here that are used to query HA and push those results into KWGT. There's also a couple tasks that normalize date and times for active charging calculations.
After the above is imported go to Profiles and create a new profile.
- Chose Event as the type of profile
- In the filter line at the bottom type "auto" and select autoremote
- Click on the pencil icon to configure
- Click on Message Filter and enter "Re" without the quotations
- Click OK
- Check the box for Exact Message
- Click back twice and Select "MME Status"
- Go into the MME Status Task and click on the run (play) button in the bottom left.
Step #7:
- Unzip the attached file.
- Create a 4x4 Widget using KWGT and resize the widget to be a square that takes the top half of the screen. NOTE: I have not tested this on different size devices. I am using a 5x5 app grid which isn't standard. But everything can be configured for your device.
- Click on the widget to go into the settings. Import the below file that was extracted from the zip.
- Profit
For anyone who just blindly followed my directions here's what we did in review:
- We first created a boolean to trigger an event in Home Assistant
- We then created an automation to monitor changes to the MME via the integration with FordPass
- We then created a rest command that could be executed in HA
- Then we created an automation to execute the rest command should the boolean be triggered by the automation used to monitor the status of the vehicle.
- We created a token and configured Tasker to be able to query and execute commands on our HA instance
- Moving on we told the phone to look for any message inbound that was simply "Re"
- We created a profile to execute a task when this message is received
- The task has 25 queries for data from HA and 25 pushes of received data to KWGT
- We created 4 executable actions to control the car
- In KWGT you really did nothing, but I spent hours coding the colors to change, text to change, buttons to appear and disappear and created the custom layout in Photoshop.
You should be able to look around and see how I coded things to work. Anywhere you see a little calculator icon is where there's custom code controlling the behavior of that object. Most of the time this is in the colors and visibility of layers.
Buttons to control actionable events are created as layers. Thus, for example, if the vehicle is locked then display the locked icon with a button action of unlock. In this example the layer is only present if the conditions are met. This allows the button to be able to switch between lock and unlock since lock actions in HA don't have toggle properties. Same goes for remote start.
There's other areas where I changed words because the returned results are not so pretty. You can easily modify all of this as you wish.
For the battery gradient, it goes from green > 50%, Orange > 30% and Red below that. If you go into the color calculator you'll see the formula I used for that, you can change those ratios or colors as you wish.
Have fun!
To Do:
Add high tire PSI warning (currently only reports low)- Add global alert icon for any issue
Add FordPass message count as icon badge countFix charging status indicator by evaluating current time against start and end timesProvide different background images with solid car and possibly various vector images to be used for door open events.Change blue color used for ignition status and charging to mach e blueOops, forgot the rear windowsManual refresh by touching MachE logoAdd circular fill to all green/red vehicle circles
- Add location of vehicle??
- Add HVB battery status??
- Add remote start remaining duration??
- Add tracker location??
Attachments
-
1.6 MB Views: 92
Last edited: