【发布时间】:2020-03-25 15:45:22
【问题描述】:
我想在时间序列图中将字符串值显示为布尔值或 int 值(数据来自家庭助理)
我有什么:
> 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
我想做这样的事情:
> 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
这可能吗?
主要目标是创建一个类似this的图表
编辑
我没有设法让它与 InfluxDb 一起使用。我将 homeassistant 的主数据库更改为 PostgreSQL。 使用 PostgreSQL 作为 Grafana 中的数据源,我确实设法使用以下查询获得了所需的图形:
> 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;
【问题讨论】:
-
你有没有得到这个工作?显然,我们都在尝试在格拉法纳重建家庭辅助气候图表。
-
@JohanHenkens,我更新了主帖
标签: grafana influxdb home-automation