I would like to show a string value as a boolean or int value in a timeseries graph (data coming from home-assistant)
What I have:
> select temperature, hvac_action_str from state where entity_id = 'my_entity_id'
name: state
time temperature hvac_action_str
---- ----------- ---------------
1574189734402651904 20 idle
1574189824323437056 19 idle
1574190158807940864 19 heating
1574190462736049920 19 heating
1574190766798977024 19 idle
I would like to do something like this:
> select temperature, (hvac_action_str == 'heating' ? 1 : 0) as isHeating from state where entity_id = 'my_entity_id'
name: state
time temperature isHeating
---- ----------- ---------------
1574189734402651904 20 0
1574189824323437056 19 0
1574190158807940864 19 1
1574190462736049920 19 1
1574190766798977024 19 0
Is this possible?
The main goal is to create a graph like this
Edit
I did not manage to get this to work with InfluxDb. I changed the main database of homeassistant to PostgreSQL. With PostgreSQL as datasource in Grafana I did manage to get the desired graph using following query:
> SELECT
created AS "time",
CAST(attributes::json->>'current_temperature' AS float) AS "current_temperature",
CAST(attributes::json->>'temperature' AS float) AS "temperature",
CASE WHEN attributes::json->>'hvac_action' = 'heating' THEN CAST(attributes::json->>'current_temperature' AS float) ELSE 0 END AS "isHeating",
state AS "state"
FROM states
WHERE
entity_id = 'my_thermostat' AND
$__timeFilter(created)
ORDER BY created;