Open electricdelicate opened 1 year ago
[EDIT] To provide everybody with a fix - without the need to read though this issue - here is a suggested solution:
With the Update to the SENEC Application v825, the integration can not communicate via http - https is required! - there is a confirmed fix available here: https://github.com/marq24/ha-senec-v3/releases/tag/3.0.5
Detailed Info & Instruction when you want to change to this fixed version
Please note, that with v0825 Senec has (temp) removed STATISTICS so that some Sensors are currently not available. A possible alternative (right now) is discussed here: https://github.com/marq24/ha-senec-v3/issues/4
[ORIGINAL] I assume you have already tried to remove the integration completely - and reinstalled it afterwards?...
When you open the original web-interface of your senec -> can you share some information what you see in the Browser DeveloperTools Network section?
I assume you have already tried to remove the integration completely - and reinstalled it afterwards?...
When you open the original web-interface of your senec -> can you share some information what you see in the Browser DeveloperTools Network section?
Hi,
no remove but the reinstall option. I guess the issue is come from the http to https change. http:// ** dont work anymore but https://**
... so you say, that after a system update your senec device is ONLY accessible via https - even from your LAN?
... so you say, that after a system update your senec device is ONLY accessible via https - even from your LAN?
Of course from my LAN.
give me a short while to add a http/https switch
Exact the same error here. HTTPS working locally.
The switch to HTTPS is part of the recent senec update which apparently is rolling out to all systems since yesterday.
The guys over at solectrus already fixed this, there are more infos in this thread: https://github.com/solectrus/senec-collector/issues/224
It seems there are also changes in lala.cgi json response. At the moment i am on the old version, as soon as i get the update i can post the full json from my v2.1 if you need it.
as soon as i get the update i can post the full json from my v2.1 if you need it. that would be hightly appriciated! - so you are able to deal with postman I guess - cool!
If you like you can have a look here for an updated version -> https://github.com/marq24/ha-senec-v3/issues/3
Just as reminder - all you do, you do on your own risk!
I just got an update on my v2.1 to version 0825. Webinterface is still http, and this integration still works.
But this version seems to be a bit broken. Display.html (whith uppercase D) stays blank.
Log.html (with uppercase L) is completely broken, it tries to fetch the logfile with path log/2023/08/30.log
(lowercase L) which does not work (Unauthorized error), but by hand with uppercase L Log/2023/08/30.log
this works.
Maybe this is just an step to the next version...
After an hour, the webinterface updated itself and i now get the version with https.
@marq24 json responses of all three requestst from your master branch. Interesting are these VARIABLE_NOT_FOUND values, i think they are now in different fields.
@marq24 json responses of all three requestst from your master branch. Interesting are these VARIABLE_NOT_FOUND values... I hope you are one the "development" branch [when you used the pre3.0.5https...
But I read the positive message - that it works in general... right? -> would be cool, if we can continue the discussion then in the fork repo ;-)
I am currently at work and only did the three post tests. Today in the evening i will switch to your fork and will give you an response there.
I can confirm the change to htps on the latest version on my v2.1. http is no longer available.
EDIT: I just checked on the SENEC webinterface if there's any chance to enable http again - but no. There is no parameter available.
So to "close" this issue here and provide some additional information;
With the Update to the SENEC Application v825, the integration can not communicate via http - https is required! - there is a confirmed fix available here: https://github.com/marq24/ha-senec-v3/releases/tag/3.0.5
A short tutorial how to switch to the other fork is available here
Please note, that with v825 Senec has (temp) removed STATISTICS
so that some Sensors are currently not available.
Hi, so I've 3.0.5 set, but still have the "VARIABLE_NOT_FOUND" at some of the sensors, how to fix that?
@Kuechenfenster there is no fix for that because it seems Senec removed this variables at least in Senec Home V2.1.
In https://github.com/marq24/ha-senec-v3/issues/4 is an workaround documented using Home Assistans Helpers with Riemann sum integral to get this long time stats.
You should stay away from Riemann sum integrals if you can since those can with time differ wildly from what the battery reports itself.
The totals in kWh are still there to download from mein-senec.de und updated there every 5 minutes, so I would prefer using that. @mstuettgen wrote a basic but working python script to bring these numbers into home assistant via MQTT (I helped): https://github.com/mstuettgen/homeassistant-addons/tree/main/senecweb2mqtt
I would prefer to use those numbers if possible instead of calculating them myself. Because every time your calculation routine is interrupted, it starts differing from what the battery calculates itself. And you will also never get the temporal resolution to accurately calculate the numbers in changing weather.
You should stay away from Riemann sum integrals if you can since those can with time differ wildly from what the battery reports itself....
I am in contact with mstuettgen and the "plan" is (not a promise) to integrate the mein-senec web-access in the integration... but of course we need some time
Senec Home V2 and V3 firmware was updated. You can identify the new version with the MCU: 825; GUI: 966; NPU:2309; bootloader: 2307 versions numbers. With this new release the web server will not longer respond in HTTP, but only in HTTPS.
You should stay away from Riemann sum integrals if you can since those can with time differ wildly from what the battery reports itself....
I am in contact with mstuettgen and the "plan" is (not a promise) to integrate the mein-senec web-access in the integration... but of course we need some time
You really only have to tell the Senec class in pysenec/init.py the login data for mein-senec.de and then poll the values every 5 minutes and overwrite the values in self._raw["STATISTIC"], so that nothing really changes for the rest of the integration.
I don't really want to create yet another fork of this integration and then do a hack job with adding the polling since I don't really have much experience with python in home assistant. So I'd prefer if you did this.
But it doesn't seem that big of a deal. I added polling of the lala.cgi to the script from mstuettgen and have been using that for the last 24 hours without any problems (and will probably even stick to that for the foreseeable future). So adding the polling of mein-senec.de to the integration shouldn't be that time consuming if you know your way around integrations.
Edit: If I find the time, I might just do that hack job and make a pull request on your repo.
I spend almost the complete afternoon trying to get a working version of https://github.com/mstuettgen/homeassistant-addons/blob/main/senecweb2mqtt/senec_webgrabber.py with aiohttp (instead of request - since aiohttp is the core engine in HA - at least in the current senec-intg)...
Here is my 'failing' code... https://gist.github.com/marq24/38939eede1b710bbbf532361b4729058
the login/auth is not working for what ever reason... Looking forward for a working version...
I spend almost the complete afternoon trying to get a working version of https://github.com/mstuettgen/homeassistant-addons/blob/main/senecweb2mqtt/senec_webgrabber.py with aiohttp (instead of request - since aiohttp is the core engine in HA - at least in the current senec-intg)...
Here is my 'failing' code... https://gist.github.com/marq24/38939eede1b710bbbf532361b4729058
the login/auth is not working for what ever reason... Looking forward for a working version...
And what about the suggestion above from Bobthebuilder4711?
And what about the suggestion above from Bobthebuilder4711?
without going into the details... if it would had been 'that easy' (for me), than I would not had spend 8h+ trying to get exactly THAT to work - but I had no success... (but this does not mean anything - I am python newbee) - So any HELP is hightly appriciated - I do this in my free time.
Everybody is invited to contribute to the existing sources and create a PR if he has a working solution.
@electricdelicate The integration should be done properly and if aiohttp is the way to go with home assistant then trying it in a much simpler test program seems like the right path to that goal.
I'll have a go at it myself and will then probably write @marq24 an email if he checks the one I've found.
@electricdelicate The integration should be done properly and if aiohttp is the way to go with home assistant then... I'll have a go at it myself and will then probably write @marq24 an email if he checks the one I've found.
looking forward to this - as I said - this code here is IMHO the 'aiohttp' version of the 'senec_webgrabber.py' https://gist.github.com/marq24/38939eede1b710bbbf532361b4729058 - but this code does not work...
@marq24 i created a quick POC based on your code, but using the senec App API. https://gist.github.com/neubi4/8545db537531e90f3ad5f0f11306a3f7
Its only quick and dirty and gets the current today data which are in Wh, so there needs more work to be done, but maybe this helps. I also have more time next week if you need more help. There is a bit of documentation for the App API here: https://documenter.getpostman.com/view/10329335/UVCB9ihW
What seems to be missing is the total data of the complete lifetime from an system. You can view this in the App using a custom time range, so it also should be possible using the API, it just needs to be sniffed in the network traffic.
❯ python ./run.py
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:__main__:***** update(self) ********
DEBUG:__main__:***** authenticate(self) ********
INFO:__main__:Login successful
DEBUG:__main__:***** get_devices(self) ********
DEBUG:__main__:***** update(self) ********
DEBUG:__main__:***** update_stats(self) ********
DEBUG:__main__:Results:
DEBUG:__main__:********* energy_entities ***************
DEBUG:__main__:stromerzeugung: 4693.359375
DEBUG:__main__:stromverbrauch: 4800.0
DEBUG:__main__:netzeinspeisung: 856.4453125
DEBUG:__main__:netzbezug: 222.16796875
DEBUG:__main__:speicherbeladung: 1894.04296875
DEBUG:__main__:speicherentnahme: 2638.671875
DEBUG:__main__:wallbox: 0.0
DEBUG:__main__:********* power_entities *****************
DEBUG:__main__:********* battery_entities *****************
DEBUG:__main__:speicherfuellstand: 13.244443893432617
DEBUG:__main__:autarkie: 95.38
Thanks @neubi4 - I am sorry that I did not mentioned this detail here - using the (mobilApp?)-API (getting a token and use that with the (via the postman "documented") API is working... That was one thing I also tried during my session yesterday - even tried to use the token with the alternative requests... also tried different encoding schemes - none of them has been successful... my-integration-wip-code
I'll keep this "documented"-API as fallback scenario - IMHO the code from @mstuettgen "have-to" work with the aiohttp client - even if this means, that aiohttp needs an update...
[WARNING-NERD-STUFF ON]
when you are enable the redirect logging, then you can compare 'request
' vs 'aiohttp
'... When you reqeust (initialy) https://mein-senec.de/auth/login
at a certain point you will receive a 302 to https://mein-senec.de/oauth2/authorization/login-portal
- and this request will be responded with another redirect to https://mein-senec.de/auth/oauth2/authorize?response_type=code&client_id=login-portal&scope=user&state=[RANDOM-STRING-HERE]%3D&redirect_uri=https://mein-senec.de/login/oauth2/code/login-portal
- and THIS redirect will be handled (IMHO) different by aiohtto
(compared to request
...
The Location
header of this last request includes a parm-encoded 'redirect_uri' (https://mein-senec.de/login/oauth2/code/login-portal) itself - IMHO request
processing this Location
instruction correctly... while aiohttp
does not - I even tried to patch my aiohttp-client to handle the redirect_uri attr -> but without success - in between a additional code
has to be calculated/read - and this is then failing also with a 401.
So you see - I tried already 'some' stuff... [WARNING-NERD-STUFF OFF]
I've been trying with a minimal example that just tries to login, but I'm always just getting error code 401 back, no matter what I try.
Is there a reason why the requests library can't be used in an integration? Is it not available in hass?
I've been trying with a minimal example that just tries to login, but I'm always just getting error code 401 back, no matter what I try.
welcome to my world (of yesterday)... at least we can agree, that's not just as simple as though...
Is there a reason why the requests library can't be used in an integration? Is it not available in hass?
I am far away from being a hass expect - all what I can say right now is, that in all the integrations I have here locally the integration get a web-session object from hass - and this object is always a aiohttp... There might be the possibility to create a own session within the integration...
... in the meantime I can at least confirm, that aiohttp causing/have a cookie issue... with a patched CookieJar I have some working code
I've looked into how other integrations do this and the spotify integration uses OAuth2Session, so I googled that and landed here: https://developers.home-assistant.io/docs/api_lib_auth/ where it says: "If you are using requests,..." with examples.
So there is nothing stopping you from just creating your own session with requests. Just won't run asynchronously. But is that really important?
So there is nothing stopping you from just creating your own session with requests. Just won't run asynchronously. But is that really important?
nothing is stopping you either... When the Spotify integration works flawless for you and if you believe it's a smart move when running requests with 10+ redirects synchronously on your ha installation then that's fine.
For some strange reason I am currently interested in the root cause of the issue with aiohttp (and provide a fixed version)... which is the cookie handling (finding the "best-matching" cookie instead of the last-received-matching cookie).
... and beside that - sun is shining - so I probably will spend some time on the bike too ;-)
As I previously said: I'm currently happy with just using the modified MQTT script and doubt I'll be changing that in the foreseeable future. I have to use MQTT anyway since I've also got a bluetti battery that sends its values to HA that way. (Which is the reason why we came up with that solution for the senec home v4 in the first place.)
I just didn't want you to get hung up on problems with aiohttp if you don't really have to. If you still want to then go for it.
Edit: And it seems like our home v2.1 forgot that it is supposed to poll our external inverters. Since yesterday morning it thinks that the sun exploded. Guess I'll have to call the installer again on Monday and hope he wants to visit us again. In the meantime I can at least get the data directly from the inverters with the SMA integration...
For those who does not like to use riemann-sum-integral platform - I just released an 'working' mein-senec.de web-api integration-addon... when you like to give it a try -> https://github.com/marq24/ha-senec-v3/issues/3#issuecomment-1698659083 [switch-fork-instructions]
Sounds great! Thank you for your work! Will it be possible to only use the values from Mein-Senec? I own a v4 and as you know, I can’t connect to it locally.
Sounds great! Thank you for your work! Will it be possible to only use the values from Mein-Senec? I own a v4 and as you know, I can’t connect to it locally.
Of course you can... just select 'SENEC.Home V4/SENEC.Home V4 hybrid' from the initial combo box and you will be guided through the setup process...
First Tests are positive. Setup was super easy 👍 great work! The values are correct but within the wrong range. So I get values in W but they should be kW instead. See a screenshot attached. What else I can provide you for debugging?
Best greetings
First Tests are positive. Setup was super easy 👍 great work! The values are correct but within the wrong range. So I get values in W but they should be kW instead.
upsi - please find an update version here... https://github.com/marq24/ha-senec-v3/releases/tag/3.0.6-test-04
I guess you have to remove & reinstall the integration to get finally the correct values
I was able to change the units within the entities of the device directly. But thanks for fixing.
Works for me - anyone knows why the energy dashboard in HA still has the old values of the old integration (cache was already cleaned)? And how can I provide the new entities to it? The dropdown does not provide the correct list of values
@jnsness please have a look here - https://github.com/marq24/ha-senec-v3/issues/4 in th https imp by SENEC the statistics data is missing - there are two possible solutions...
does anyone see a chance that we get a fix for the http/https issue in this repository as well?
does anyone see a chance that we get a fix for the http/https issue in this repository as well?
Only if you get the author of this repository to become active again. He might be on vacation currently or something like that but if nothing happens in the next few weeks then you can consider this repository as abandoned.
If I were you, I would switch to the integration of @marq24 and then use template sensors (example here: https://github.com/marq24/ha-senec-v3/issues/4#issuecomment-1704052799 The text is in German, but the example template sensor should be self-explanatory). Then use the template sensors where ever you want to use them and if that integration ever gets abandoned you can always just change the sensors that the template sensors get their data from.
Just be aware that some sensors are in W and some are in kW. But you can just divide the template's state by 1000 or multiply it by 1000 to get the desired result.
Migrating to @marq24 solution and using templates sensors for the dashboard I did but needed to rollback to the last backup because I lost all statistic / history data. How can we prevent that? Just use the same entity ID?
Migrating to @marq24 solution and using templates sensors for the dashboard I did but needed to rollback to the last backup because I lost all statistic / history data. How can we prevent that? Just use the same entity ID?
would that help https://github.com/marq24/ha-senec-v3/issues/11 ? But your assumption is also valid - as @bobthebuilder4711 has suggested using template sensors (to archive the final matching)...
would that help marq24#11 ? But your assumption is also valid - as @bobthebuilder4711 has suggested using template sensors (to archive the final matching)...
I myself have done both. I have deactivated (not deleted!) the old integration so that the energy dashboard still knows about that data.
And then I have set up templates so that in the future the data source can change if it has to. I've added the new sensors into the templates and then have added the templates to the energy dashboard.
In the future I will probably play around with the database and write an SQL script to migrate the historical data of the old integration over to the templates. But for now I'm fine with the old integration simply being deactivated.
Alright - then I will aim for that. Do you want to provide the template scripts? I think you are using total_increasing at every template?
The first one is an example for one of the "total" sensors. If your source sensor isn't in kWh but in Wh but you want the template sensor in kWh then the state should look like this: {{ float(states('sensor.the_source_sensor')) / 1000 }}. The unique_id is needed internally by Home Assistant (see here why: https://www.home-assistant.io/faq/unique_id/). The entity_id will be constructed from the name and will be (in this case) sensor.never_changing_sensor_pv_production_total.
The second one is an example for the "now" sensors and has different unit, device and state class entries. You don't need these for the HA energy dashboard, but they're good if you want to construct something like the now defunct display.html.
template:
- sensor:
- name: "Never Changing Sensor PV Production Total"
unique_id: "something unique like a UUID: https://www.uuidgenerator.net/"
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
state: >
{{ float(states('sensor.the_source_sensor')) }}
- sensor:
- name: "Never Changing Sensor PV Production Now"
unique_id: "something unique like a UUID: https://www.uuidgenerator.net/"
unit_of_measurement: kW
device_class: power
state_class: measurement
state: >
{{ float(states('sensor.the_source_sensor')) }}
This code needs to be written to the configuration.yaml. You can do that with the File Editor Addon.
The templates need a reboot to become active. And please test this first with one template.
does anyone see a chance that we get a fix for the http/https issue in this repository as well?
this might be a valid option as the guys over at solaranzeige.de managed to get their integration working again by just changing their data collector to https (php, libcurl, https://solaranzeige.de/phpBB3/viewtopic.php?p=29873&sid=94fb769eaa6e45bf00bbb7003fbad6fa#p29873). Furthermore it might be worth investigating establishing a http to https proxy running as MITM (will investigate over the weekend) - however Senec will probably introduce more breaking changes (obviously they don't care about community projects) so the proxy might not be a final solution. Has anyone tried to fix this repository by just switching it to https wherever possible?
After the recent firmware update, my Senec Home 2.1 becomes unavailable immediatly in home assistant. Nothing helps.
Please fix it.
Thank you.