Closed Octofinger closed 2 months ago
I ran this Python script to test the retrieval of history. I ran it from a separate PC on the same network. It returns a complete list of sensor history, so still can't reproduce the EMHASS behavior. (secrets masked)
import pandas as pd
from requests import get, post
days_list = pd.date_range(end='2024-04-17', freq='D', periods=5)
print(days_list)
print(days_list[0].isoformat())
day = days_list [0]
var = 'sensor.template_emhass_no_var_load_2'
hass_url= 'https://my.homeassistant.url:8123/'
long_lived_token = 'XXXXXXXXXXXXXXXX'
url = hass_url+"api/history/period/"+day.isoformat()+"?filter_entity_id="+var
headers = {
"Authorization": "Bearer " + long_lived_token,
"content-type": "application/json",
}
# Then once that all this is defined there is no much to it than this:
response = get(url, headers=headers)
# And extract the data >> This is where your code is failing so check this part:
data = response.json()[0]
# If successful then print
print(data)
[{'entity_id': 'sensor.template_emhass_no_var_load_2', 'state': '694.05', 'attributes': {'unit_of_measurement': 'W', 'device_class': 'power'}, 'last_changed': '2024-04-12T22:00:00.928736+00:00', 'last_updated': '2024-04-12T22:00:00.928736+00:00', 'context': {'id': '01HVG824J3QD58P2P1KHNK5EBW', 'parent_id': None, 'user_id': None}}, {'entity_id': 'sensor.template_emhass_no_var_load_2', 'state': '693.03', 'attributes': {'unit_of_measurement': 'W', 'device_class': 'power'}, 'last_changed': '2024-04-12T22:00:02.861105+00:00', 'last_updated': '2024-04-12T22:00:02.861105+00:00', 'context': {'id': '01HVG824J3QD58P2P1KHNK5EBW', 'parent_id': None, 'user_id': None}}, {'entity_id': 'sensor.template_emhass_no_var_load_2', 'state': '694.55', 'attributes': {'unit_of_measurement': 'W', 'device_class': 'power'}, 'last_changed': '2024-04-12T22:00:05.114414+00:00', 'last_updated': '2024-04-12T22:00:05.114414+00:00', 'context': {'id': '01HVG824J3QD58P2P1KHNK5EBW', 'parent_id': None, 'user_id': None}}, {'entity_id': 'sensor.template_emhass_no_var_load_2', 'state': '685.56', 'attributes': {'unit_of_measurement': 'W', 'device_class': 'power'}, 'last_changed': '2024-04-12T22:00:17.870891+00:00', 'last_updated': '2024-04-12T22:00:17.870891+00:00', 'context': {'id': '01HVG824J3QD58P2P1KHNK5EBW', 'parent_id': None, 'user_id': None}}, {'entity_id': 'sensor.template_emhass_no_var_load_2', 'state': '684.04', 'attributes': {'unit_of_measurement': 'W', 'device_class': 'power'}, 'last_changed': '2024-04-12T22:00:20.125773+00:00', 'last_updated': '2024-04-12T22:00:20.125773+00:00', 'context': {'id': '01HVG824J3QD58P2P1KHNK5EBW', 'parent_id': None, 'user_id': None}}, {'entity_id': 'sensor.template_emhass_no_var_load_2', 'state': '689.17', 'attributes': {'unit_of_measurement': 'W', 'device_class': 'power'}, 'last_changed': '2024-04-12T22:00:32.871763+00:00', 'last_updated': '2024-04-12T22:00:32.871763+00:00', 'context': {'id': '01HVG824J3QD58P2P1KHNK5EBW', 'parent_id': None, 'user_id': None}},
...
I need to find the time to try to replicate this. In the meantime can you provide the logs from the add-on after a fresh restart of the add-on? It's just to check the information printed on the logger about how data is retrieved from HA. It is true that HA core and EMHASS on docker standalone mode are the least common installation methods these days.
OMG, now the problem is gone. I haven't done anything. No restarts, no config changes, no nothing... I seriously have no friggin idea what happened. The log errors are gone and the optimization and data publisher runs without issues.
I'll close this. If anything like this happens again, I'll try to set up a dev environment with a clone of this repo to try to get more details before posting anything.
Thanks a million for your engagement in this. emhass is key to making my solar facility more profitable and I really appreciate this. I bought you some coffee.
Describe the bug EMHASS
naive-mpc-optim
fails because it can't read my load sensor. This just started one early morning without me having made any changes to neither configuration, nor made any restarts.The logs show the following error message:
To Reproduce This happens every time I try to call the optimization.
Expected behavior EMHASS should be able to read the sensor's value. It clearly has a history if I look at it in HA:![image](https://github.com/davidusb-geek/emhass/assets/34031086/3c0dbc82-8b6b-4524-b766-d6c8359e5e7a)
Screenshots If applicable, add screenshots to help explain your problem.
Home Assistant installation type
Your hardware
EMHASS installation type
Additional context I have tested retrieving the sensor history using curl from within the emhass container using the same HA URL and access token as specified in![image](https://github.com/davidusb-geek/emhass/assets/34031086/11610177-0a14-4cb2-99e4-ba043f8728d3)
secrets_emhass.yaml
and it works well. I have tried creating a second load sensor in HA, but that cannot be read either by EMHASS. I have tried using the sensor in an ML forecaster fit call from EMHASS web UI, but only with the same result: