Hello,
I'm using HA with a luxPower inverter/battery system, I monitor and control the inverter with my own python code which interfaces with HA via its API.
It all works very well except occasionally something gets stuck and readings stop updating and I have to manually click a button (button card)
on the HA dashboard to refresh the LUX Data.
For the life of me I cannot figure out how to automate this (single click) from my python code via the API.
Sorry if this is a daft question, any help gratefully received.
Do the entities report unknown or unavailable or do the values stop updating?
Unknown or unavailable states are easy to trigger from, e.g.
trigger: state
entity_id: sensor.foo_bar
to: unknown
If the values just stop updating then you need to determine how long you want to wait to make sure they are really stuck and not just staying on the same value because that is what is happening in reality. e.g if that value is 30 seconds then you can trigger an automation like this:
trigger: state
entity_id: sensor.foo_bar
to: # null to will trigger on any state that exists continuously for 30 sec.
for:
seconds: 30
Thanks for responding. The entity values just stop updating, I can easily detect this with my external python code by checking the "date of last update" entity. The only problem is automating the refresh process from my external python code VIA the HA API. I guess this is really an API question.
Thanks again for your input.
Yes, thanks, I'm aware of that documentation, it's not overly helpful.
I've tried calling what I believe to be the refresh service, ie:
"http://192.168.0.29:8123/api/services/luxpower/luxpower_refresh_registers"
with the bearer token header and with an empty json {} field but I get an error 400 - bad syntax, which make sense.
The documentation is not clear about what other headers are required and what if any json data is needed.
Any clarification or ideas would be most helpful.
Thanks again.
Pete, thanks for that suggestion, sadly that merely changes the error (from 400) to 404
So that looks like a step backwards.
I can't help wondering if I should be putting something in the json data.
Any other ideas?
I'm probably the last guy who should comment since I know next to nothing about templates.
What I do know is that each entity has a (hidden) last_changed & last_updated property which you could use to determine how long it's been since the last update on that sensor.
Hopefully someone with more template clout than me can guide you on how to set up a trigger-based template sensor which fires if one of those properties is greater than X amount of time. You'd then be able to set up an automation to call luxpower_refresh_registers quite easily without having to involve a direct API call.
Pete, Thanks for that - it seems to work.
At least insofar as it now gives no error codes but: it's impossible to say, at the moment, if did actually do a refresh.
To find that out I'll have to wait for the next random lock-up event.
Thanks again, and also to all who have contributed, this is a good community.