OK, complete newbie here. I’ve set up HA on Proxmox and added switches, plugs, thermostats etc. What I’m now thinking about is interfacing with my solar inverter/battery to decide when to charge. So typically, I’ll be looking at the import prices for the next 24 hours, choosing the minimum cost slot and telling the battery to charge. Of course, I have to ensure that the battery won’t be empty during a high-cost slot, so I may have to use a non-optimal charging slot to carry me over. Additional inputs might be average hourly usage, expected solar generation etc.
I have a few algorithms in mind for addressing this, and I believe I could easily knock up a program to achieve this. But I don’t think I could do this sort of thing in HA script. I’m wondering if there’s a way to call an “external” program from with HA - eg, HA polls a file, mailbox or queue every hour to check if it should issue an action to charge (or even discharge)?
Any help, advice, directions will be gladly recieved!
BTW, I’m an old git who tends to think in Fortran, but I can manage other languages.
Thanks
Andy
Pretty much all your ideas are possible.
The problem sometimes is that you both need to extract data from HA and input the result data back.
It is possible but can be a bit cumbersome at times.
If you can program in JavaScript, then Node Red might be a good option and the function node there is for javascript.
But out a few more details on your ideas, like what you need of in and out and what you have available of methods for it and what language you want to use and so on.
Thanks Wally, that’s exactly the sort of info I was looking for. I can manage Javascript, but I’ll have to read up on Node Red.
You’re right, I’ll need to get data in and out of HA - typically, eg, state of charge. The logic wouls then involve populating, say, a 24-array with expected SOC from the current hour, the power prices in another array, expected solar contributions in another array etc. and then running charging scenarios against these arrays and coming up with a decision: charge, discharge or do nothing. So lots of looping!
The background to this is that a UK energy provider Octopus offers a tariff they call Agile, which has variable rates every hour (well, 30 mins actually). Sometimes they even pay you to use the electricity. The downside of course is that sometimes it’s very expensive. Similarly, export or feed-in rates vary throughout the day. This is just an interesting exercise for me at the moment, but I may implement it if it proves robust enough.
Node Red is extremely easy.
It even contains a copy of HA’s state machine, so you can make a global.get to retreive a value from HA in JavaScript.
Play a bit with Node Red and then ask.
Just to throw a couple of other options in:
You can shell out to an arbitrary executable that you have compiled and installed on the HA filesystem. The major caveat with that is that the executable must exit within 1 minute of startup (there is a fixed 1 minute timeout).
I personally like MQTT - I have an external Mosquito message broker installed so I can simply copy any state I want to MQTT (within HA) then I can fire events back to HA by posting to MQTT topics.
The key advantages of MQTT is:
- You are free to code in any language.
- Your code is largely decoupled from HA and knowledge of any HA internals **.
** - You may need to learn some very custom JSON if you want to expose external entities as HA Devices (auto-discovery) but that is optional.
Welcome!
Maybe this integration could provide the data you want, without requiring custom programming?
If you’d rather use Python, then AppDeamon is an option. It too has easy access to everything Home Assistant has on offer:
Thanks for that - more background research required, though I have come across MQseries (IBM) a good few years ago. Presumably the technology is more robust these days…
To add another option. If your data is accesable on the net in some form then you can also use the web scrap integration in HA to collect the data into HA
Stand on the shoulders of giants. Look at the code from those integrations above for ideas. Also look at integrations for other utility providers that have varying time based tariffs. Also look at electric vehicle charger integrations that are time based on utility prices. Patterns should emerge.
What integration do you have for your solar inverter/battery?
The programming algorithm is the same. Define your problem.Get data, process it, take action. Rinse and repeat.
A lot of HomeAssistant is Python based. You will get lots of hints as you examine code as to what to do to roll your own integration.
Post your progress. We might have hints and pointers.