Giter VIP home page Giter VIP logo

Comments (7)

chdao avatar chdao commented on July 25, 2024 1

This would probably be a good way for me to learn both Python and guts of ES, so I'd love to give it a go but don't take this as a "cool someone else is doing it", if I thought I had the capacity to currently do this, I wouldn't have created this ticket in the first place ;)

This is clearly not urgent and much more of a nice to have, but I'm not a huge fan of the pull method and I would rather stream my data to HASS than to read from a database.

from homeassistant-elasticsearch.

legrego avatar legrego commented on July 25, 2024

Hey @wickedsun, thanks for opening this issue.

This is an interesting idea. How do you envision this working with a query that returns multiple hits, or multiple buckets in an aggregation?

For queries that return a single hit, I could see something like this working:

elastic:
   query_sensors:
     - name: sensor_1
     query: '{"query": { "terms": {...} }}'
     field: 'my.document.field'

Where my.document.field represents a field in the document returned by the query

from homeassistant-elasticsearch.

chdao avatar chdao commented on July 25, 2024

How do you envision this working with a query that returns multiple hits, or multiple buckets in an aggregation?

That's a good question. My use case may be very specific. My thought was using geolocation from ElasticSearch to do geofencing since I have stuff going straight to Elastic. Then I thought "hey wait that'd be nice to do geofencing with", and short of rewriting the script to send to MQTT as well as ES, I don't think I can do it.

My guess would be that people who use Elastic for HASS would also like to be able to do this as usually you're going to be putting a lot more data into it other than HASS with no way of tying it into HASS.

For queries that return a single hit, I could see something like this working:

I'd also add a time constraint so that you can do last (non-empty) value only or X minutes average. I can see a scenario where someone might want to turn off the AC if the average over the last 15minutes is lower than X rather that the absolute current value, for example. Obviously this would need buckets/aggregation.

Honestly for what I want to do, last geolocation values would do the trick, but the possibilities with this would be pretty awesome since ES is very powerful.

from homeassistant-elasticsearch.

legrego avatar legrego commented on July 25, 2024

I'd also add a time constraint so that you can do last (non-empty) value only or X minutes average.

Is this something that you could solve with Elasticsearch's date math, or am I mis-understanding?

Honestly for what I want to do, last geolocation values would do the trick, but the possibilities with this would be pretty awesome since ES is very powerful.

Maybe we just take the top hit (hits.hits[0]) as the sensor value, and log a warning if more than one hit is returned? Alternatively, the component could enforce a size: 1 for document queries. A similar constraint could be placed for aggregations, but I haven't given that a ton of thought yet.

from homeassistant-elasticsearch.

chdao avatar chdao commented on July 25, 2024

My knowledge of ES is pretty bare, but I'll try answering.

It does look like date math would solve that part as you could do "now-X".

Let me explain clearly what I'm trying to do here. I'm getting readings from my car's location every ~4 seconds and this is dumped into ES. I wanted to use that for geofencing since... I already have it so why go through the trouble of setting up something on my phone like OwnTrack when I can just track my car.

I saw that there was a SQL sensor and figured there must be a ES sensor too, then. To my surprise there wasn't, hence this ticket.

from homeassistant-elasticsearch.

legrego avatar legrego commented on July 25, 2024

I was also surprised to find there wasn't an ES component, hence this one 😄. I started this one with the opposite problem though -- getting data from HASS into ES, rather than from ES to HASS. That being said, I don't see why this can't accomplish both.

I have a couple of other enhancements I'd like to work on before tackling this, so I likely won't get to this right away. PRs are welcome if you're handy with Python. I'm not a strong Python dev by any means...this was my first and only real project with the language.

from homeassistant-elasticsearch.

strawgate avatar strawgate commented on July 25, 2024

I think this might be best served by a separate device-type integration where you can add "devices" which are just elasticsearch queries

from homeassistant-elasticsearch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.