So first add a new sensor that shows the change of the CO2 sensor in the last minute. 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 status bar:
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.
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 be generated 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 removed the quotes.
I put the curl command into
co2_status.sh and call it from waybar like this: