Ok, since it is so troublesome to access long term statistics using the SQL integration due to the fact that it doesn’t support parameters or templates, I came up with a real “hack”. In theory it should work, but I am limited by my unix/HA skills. I am a front end developer by trade and have very little expertise using stuff like ssh or bash commands. I have never used Unix in my life (windows/mac person). This is what I har so far:
And this just give me “unknown” and error code 127. From reading countless threads here I understand that has something to do with different docker containers or something…
Someone here suggested that I need to add some commands before my actual command to make this work:
If I put that stuff before my sqlite3… it should work and the sensor should return 23211 or what ever number the count is. Note, I only plan to return scalar values, numbers and text, never lists.
So, my problem is that I have no clue what the above ssh line is or what I should do to make it work on my HA device. I have read the posts, but still clueless. I have a HA Green and a windows pc with windows 11. I have installed the add on “terminal & SSH”. Thats about it.
Thank you, but as I mentioned in my post, the SQL integration has one BIG flaw, and it is that I cant use parameters or templates for the queries. A simple {{parameter }} would have solved my issue, but somehow the developers didn’t think that was needed.
I had working code and a cumbersum and “hacky” solution using helpers, automations, scripts and the REST-api, but for some equally strange reason they decided not to include LTS in their “statistics” API. Go figure… and it is not mentioned anywhere in the documentation either.
This is the only solution that I have tried that actually might work to dynamically query long term statistics. I can use parameters for my queries, I can use whatever SQL query I want and I can finally easily access LTS. All I need is to get that fricki´n command_line sensor to work.
It is stupidly complicated, I know, but after having spent several days with utility meters, REST-API etc etc etc, this is my final idea…
Intriguing. I have never used node red, and was kind of hoping to avoid any rabbit holes like that (big tools that takes lots of time to learn).
I will have a look at this, any documents, tutorials or code examples that can help me out along the way? I have found this integration in HACS, is that the one I need? HACS – Home Assistant
I finally found a working solution with Node Red. It is stupidly complicated to access LTS this way, but the values are finally there. I have lots of work left to do before it is totally solid, but now I am happy to finally show the total on my energy graph page