davidusb-geek / emhass

emhass: Energy Management for Home Assistant, is a Python module designed to optimize your home energy interfacing with Home Assistant.
MIT License
278 stars 54 forks source link

Feature request: Log message in emhass about incomplete cost price data #17

Closed overas closed 1 year ago

overas commented 2 years ago

Nordpool have sometime missing tomorrow cost data. nordpool 08-35

When trying to pass the incomplete cost data as list from the command line the log says:

2022-08-28 08:38:29.481 DEBUG (MainThread) [homeassistant.components.shell_command] Stdout of command: `curl -i -H "Content-Type: application/json" -X POST -d '{"load_cost_forecast": {{ ((( state_attr('sensor.nordpool', 'raw_today') + state_attr('sensor.nordpool', 'raw_tomorrow')) |map(attribute='value')|list)[:48]) }}' http://localhost:5000/action/dayahead-optim`, return code: 0:
b'HTTP/1.1 400 BAD REQUEST\r\nContent-Length: 167\r\nContent-Type: text/html; charset=utf-8\r\nDate: Sun, 28 Aug 2022 06:38:29 GMT\r\nServer: waitress\r\n\r\n<!doctype html>\n<html lang=en>\n<title>400 Bad Request</title>\n<h1>Bad Request</h1>\n<p>The browser (or proxy) sent a request that this server could not understand.</p>\n'
2022-08-28 08:38:29.481 DEBUG (MainThread) [homeassistant.components.shell_command] Stderr of command: `curl -i -H "Content-Type: application/json" -X POST -d '{"load_cost_forecast": {{ ((( state_attr('sensor.nordpool', 'raw_today') + state_attr('sensor.nordpool', 'raw_tomorrow')) |map(attribute='value')|list)[:48]) }}' http://localhost:5000/action/dayahead-optim`, return code: 0:
b'  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r100   501  100   167  100   334  29896  59792 --:--:-- --:--:-- --:--:--   97k\n'

Is there any way emhass can log a message about missing tomorrow cost data.

davidusb-geek commented 2 years ago

I guess that this can be done. Check for any missing values on passed data and throwing an error or a warning on this..

davidusb-geek commented 1 year ago

Hi. I just added warning messages if passed list values contains non numeric items like null, void, nan, etc. However, as this original issue was posed, it is impossible to add a log message because in your error the curl command never reach EMHASS because of the non-numeric values. So you should solve this inside your template of the shell command.