{"id":433,"date":"2020-12-10T12:01:32","date_gmt":"2020-12-10T12:01:32","guid":{"rendered":"https:\/\/carson.fenimorefamily.com\/?p=433"},"modified":"2020-12-10T12:01:34","modified_gmt":"2020-12-10T12:01:34","slug":"influxdb-queries-on-homeassistant-data","status":"publish","type":"post","link":"https:\/\/carson.fenimorefamily.com\/?p=433","title":{"rendered":"InfluxDB Queries on HomeAssistant Data"},"content":{"rendered":"\n<p>I recently added in influx db + grafana + mariadb to one of my HA instances.  I was surprised at how easy it was to get HA happy.  Essentially nothing more than running the docker instances for each of these components and adding minimal yaml to HA.<\/p>\n\n\n\n<p>When i went to query the data there were a few surprises that I thought I&#8217;d note.  First, as noted in <a href=\"https:\/\/community.home-assistant.io\/t\/missing-sensors-in-influxdb\/144948\">https:\/\/community.home-assistant.io\/t\/missing-sensors-in-influxdb\/144948<\/a>, HA puts sensors that have a unit name inside a <em>measurement<\/em> of that name.  Thus if i show measurements that match my model_y, for example, all i get are binary (e.g. unittless) sensors:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&gt; show measurements with measurement =~ \/sensoricareabout\/\nname: measurements\nname\n----\nbinary_sensor.sensoridontcareabout1\nclimate.sensoridontcareabout2\ndevice_tracker.sensoridontcareabout3\n...\n<\/pre>\n\n\n<p>However if i query series, similarly, i see the measurement i care about:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&gt; show series where &quot;entity_id&quot; =~ \/sensoricareabout\/\nkey\n---\n\u00b0F,domain=sensor,entity_id=sensoricareabout_foo_1\n\u00b0F,domain=sensor,entity_id=sensoricareabout_foo_2\n<\/pre>\n\n\n<p>Thus, oddly, to query the data i want i form a query something like this:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n select value from &quot;\u00b0F&quot; where entity_id = 'sensoricareabout_foo_1'\n<\/pre>\n\n\n<p>A couple things.  So, it is odd to me to have to query from what I essentially view as a table \u00b0F&#8230; but that is probably more HA&#8217;s fault than influxdb.  Second, i think the quoting is a little weird.  Note above that the measurement is double quoted, whereas the tag is single quoted.  This is important.  You can sometimes (maybe?) leave the double quotes off the former but the latter must <em><span style=\"text-decoration: underline;\">strictly<\/span><\/em><span style=\"text-decoration: underline;\"> be single quotes&#8230;<\/span><\/p>\n\n\n\n<p>The moral of the story is that if you want to find the data you are looking for you need to look under &#8216;%&#8217; or the actual unit of measurement.  For example in grafana i would:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>click on explore<\/li><li>select &#8216;%&#8217;<\/li><li>Add a where clause to filter by entity_id<\/li><li>Possibly find my series there&#8230;<ul><li>But if not remove the where, and switch from % to the unit of measurement, and repeat by adding the where clause<\/li><\/ul><\/li><\/ul>\n\n\n\n<p>This all works well but is a little unintuitive and might make one think HA has forgotten to put the data into influx.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/carson.fenimorefamily.com\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-10-at-6.59.44-AM.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"506\" src=\"https:\/\/carson.fenimorefamily.com\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-10-at-6.59.44-AM-1024x506.png\" alt=\"\" class=\"wp-image-434\" srcset=\"https:\/\/carson.fenimorefamily.com\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-10-at-6.59.44-AM-1024x506.png 1024w, https:\/\/carson.fenimorefamily.com\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-10-at-6.59.44-AM-300x148.png 300w, https:\/\/carson.fenimorefamily.com\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-10-at-6.59.44-AM-768x379.png 768w, https:\/\/carson.fenimorefamily.com\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-10-at-6.59.44-AM-1536x758.png 1536w, https:\/\/carson.fenimorefamily.com\/wp-content\/uploads\/2020\/12\/Screen-Shot-2020-12-10-at-6.59.44-AM-2048x1011.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently added in influx db + grafana + mariadb to one of my HA instances. I was surprised at how easy it was to get HA happy. Essentially nothing more than running the docker instances for each of these components and adding minimal yaml to HA. When i went to query the data there &hellip; <a href=\"https:\/\/carson.fenimorefamily.com\/?p=433\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">InfluxDB Queries on HomeAssistant Data<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,21],"tags":[],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-containers","category-homeassistant"],"_links":{"self":[{"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=433"}],"version-history":[{"count":1,"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":435,"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions\/435"}],"wp:attachment":[{"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carson.fenimorefamily.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}