So first add a new sensor that shows the change of the CO2 sensor in the last minute to the homeassistant
This is a Derivative sensor with a time window of one minute.
This looks like this in homeassistant:
Next we create another sensor that formats the string we want for the statusbar:
The value_template is in jinja syntax and the value in the bracket is forced to have a sign in front (+ or -) using a Python-style format string.
The result looks for example like this:
CO2: 723.3 [+7.00].
Now we need to get the value from the homeassistant API to show them in the statusbar. Prerequisite is a "Long-lived access token" which we can generate on the profile view of homeassistant.
The curl and jq line to get the "statusbar_co2" sensor:
The jq command filters the list of entities to the "statusbar_co2" entity and returns the
-r removes the quotes around the result of jq.
I put the curl command into
co2_status.sh and call it from waybar like this: