lukassoo / ShellyExporters

All Shelly Exporters for Prometheus
MIT License
11 stars 1 forks source link

Config file not created / Support Shelly Plus Plug S - Gen 2 device #4

Closed HB9VQQ closed 7 months ago

HB9VQQ commented 9 months ago

I have been running docker pull lukassoo/shelly-plug-exporter:armv7

then

docker run --name ShellyPlugExporter -d -p 9918:9918 -v /etc/shellyPlugExporter:/Config lukassoo/shelly-plug-exporter:armv7

I could not find a config file in /etc/shellyPlugExporter

Thanks

lukassoo commented 9 months ago

I will take a look tomorrow and try it with that image.

Could you tell me what hardware and OS you are running this on? Also - did you create the "/etc/shellyPlugExporter" directory ?

HB9VQQ commented 9 months ago

Thank you for looking into this. I am running it on an RPi 3B with Raspian Buster The directory "/etc/shellyPlugExporter" was created when I ran docker run command

lukassoo commented 9 months ago

I installed the same OS and reproduced the issue. The config was not created and the weirdest thing was that there were no logs at all. 🤔

I built and launched the app without docker and that seemed to work without any issues. Then I tried with a freshly built docker image and... it just worked...

I suspect I might have built the image without first building the app which could result in a missing executable - nothing to run = no logs.

Anyway, I have pushed the new image and successfully tested it on the Raspberry 3B+ with Raspbian Buster installed. Delete the old one, download the new one, and let me know if it works correctly now.

HB9VQQ commented 8 months ago

Thank you, the installation is working now. docker run --name ShellyPlugExporter -d -p 9918:9918 -v /etc/shellyPlugExporter:/Config lukassoo/shelly-plug-exporter:armv7

This is my /etc/shellyPlugExporter/shellyPlugExporter.yml

`targets:

I am not using authentication. The shelly smart plug 192.168.1.22 is accessible via a web browser

Prometheus reports prometheus-shelly

In the log of the shelly smart plug I repeatedly see:

shelly_http_server.:263 No handler for '/status' shelly_http_server.:263 No handler for '/status' shelly_http_server.:263 No handler for '/status'

This is my shelly smart plug: Shelly PlusPlugS D4D4DAEB6B68| 1.0.8| 58706c2c|

lukassoo commented 8 months ago

Ok, I see what is happening here. You have the Shelly Plus PlugS - which is part of their new Gen 2 devices. These devices use a new way of communicating so unfortunately the current implementation will not work as the /status endpoint no longer exists.

I will have to write handling for these new Gen 2 devices but as I now look at the new API and the capabilities of this device it would appear that there is no way of getting the current power - they only speak of setting power levels for LED color changes. But that would mean that they have a way of measuring it so why would there be no way of getting it...

Could you please tell me or show me a screenshot of the plugs page? Is the current power usage displayed anywhere?

HB9VQQ commented 8 months ago

Thanks for your continued support. Yes it is the Gen 2 Shelly plug. Here is a screenshot image

I can make a Wireshark network traffic capture if that helps.

HB9VQQ commented 8 months ago

I took a Wireshark packet capture - 192.168.1.22 is the Shelly smart plug shellyGen2pcap.zip

lukassoo commented 8 months ago

Never mind my previous response. (now deleted)

I have found what we need - I didn't read the docs correctly. The device has a Switch component that has the Switch.GetStatus method and that returns all necessary information - including power.

I wrongly assumed that the switch component only controlled switching power On/Off. I also found out there is a "Shelly" component on all the Gen 2 devices for backward compatibility. This component provides a GetStatus method that returns info about all components.

Now that I know where to look I can implement support for Gen 2 devices.

The only issue I am facing now is no physical device to test with. I only have old plugs around and a quick Google search says installing Gen 2 firmware on old plugs is not possible/recommended.

Do you perhaps have the ability to hook one up so that I can access it remotely for testing? I have a static IP so a firewall rule to only allow my IP (would share it privately) should keep it safe from bots and other nasty stuff.

HB9VQQ commented 8 months ago

Great analysis, thanks. I have a couple of spare plugs. I could send you one by post, no problem at all. I am in Switzerland. I can of course also bring a spare plug online. Just let me know which way you prefer.

lukassoo commented 8 months ago

I think just bringing one online and forwarding a port should be enough. The firewall rule will be useful as it will be without authentication at the start so theoretically anyone would be able to get in and do whatever they want. I also intend to support authentication for Gen 2 so I will set some testing user/password.

Further info will probably include IPs so we should probably speak through DMs, do you use Discord ? I managed to get my username lukassoo as the unique id.

lukassoo commented 8 months ago

We are nearing a release version 🙂

I have uploaded docker images to Docker Hub The previous version worked nicely for almost a whole week. There was however some sort of error on the first day of it running that I could not reproduce. I added more logs to see what was causing the issue but it never happened again.

I did some more cleanup work and improved request handling in today's version. If everything works nicely for another week or so then it will be the final version and I'll update the documentation and upload the Grafana dashboard for it. The dashboard will most likely look like this: image

All the other exporters will also receive updates to the newest .NET version with all the bug fixes and improvements that I did while working on the new exporter.

pec0ra commented 8 months ago

@lukassoo just tried the new exporter with my Shelly Plus Plug S and it works well. Thank you for your work!

lukassoo commented 8 months ago

The error/exception I mentioned before has happened again, this time I got the logs:

[WRN] Request send exception: 
The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseReceived'
[INF] Attempting reconnect
[WRN] Failed to connect to web socket, exception: 
The WebSocket has already been started.
[ERR] Failed to reconnect, failing send
[WRN] Send failed, failing request
[ERR] Request response null or empty - could not update metrics
01/10/2024 17:29:56 Exception while processing request: Update metrics request failed

It seems that the web socket can get to the "Aborted" state somehow. To fix it I am now recreating the web socket when connecting so the reconnection attempt should not fail.

The fix is implemented and the docker images are updated. If you used the old images you need to remove them and download the new ones since they use the same tag.

Here are the docker run commands for convenience until the docs are updated:

ARMv7

docker run --name ShellyPlusPlugExporter -d -p 10009:10009 -v /etc/shellyPlusPlugExporter:/Config lukassoo/shelly-plus-plug-exporter:armv7

ARM64

docker run --name ShellyPlusPlugExporter -d -p 10009:10009 -v /etc/shellyPlusPlugExporter:/Config lukassoo/shelly-plus-plug-exporter:arm64

x86_64

docker run --name ShellyPlusPlugExporter -d -p 10009:10009 -v /etc/shellyPlusPlugExporter:/Config lukassoo/shelly-plus-plug-exporter:latest
lukassoo commented 8 months ago

@HB9VQQ Did something happen to the plug? This morning around 8:40 it stopped responding and the provided link is returning a connection refused error.

HB9VQQ commented 8 months ago

The IP address of the plug has changed. Need to change NAT. Mit freundlichen GrüssenRoland GafnerAm 12.01.2024 um 16:30 schrieb lukassoo @.***>: @HB9VQQ Did something happen to the plug? This morning around 8:40 it stopped responding and the provided link is returning a connection refused error.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

HB9VQQ commented 8 months ago

Should be accessible again

Von: Roland Gafner @.> Gesendet: Freitag, 12. Januar 2024 18:16 An: lukassoo/ShellyExporters @.> Betreff: Re: [lukassoo/ShellyExporters] Config file not created / Support Shelly Plus Plug S - Gen 2 device (Issue #4)

The IP address of the plug has changed. Need to change NAT.

Mit freundlichen Grüssen

Roland Gafner

Am 12.01.2024 um 16:30 schrieb lukassoo @. @.> >:



@HB9VQQ https://github.com/HB9VQQ Did something happen to the plug? This morning around 8:40 it stopped responding and the provided link is returning a connection refused error.

— Reply to this email directly, view it on GitHub https://github.com/lukassoo/ShellyExporters/issues/4#issuecomment-1889512102 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ASDK2BCR3IKZJEXV6FT2HK3YOFJGNAVCNFSM6AAAAABBB5SGFWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBZGUYTEMJQGI . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ASDK2BFEEHARJTMFHUAAZC3YOFJGNA5CNFSM6AAAAABBB5SGFWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTQT6VKM.gif Message ID: @. @.> >

lukassoo commented 8 months ago

A quick update for everyone waiting.

Unfortunately, there is a delay because I have some rather big problems with my home server. I am focusing on offloading and backing up data before it is unrecoverable. I hope that it's just a faulty cable somewhere but finding it will probably take some time of trial and error doing read/write tests to ensure this won't happen again.

lukassoo commented 8 months ago

The server is now back online and testing all images with updates and fixes. I am hoping that no more issues appear but in case there are any more issues I have not replaced the old images but made the development ones:

Feel free to use them if you want to help me test them. Let me know if anything is wrong.

I will be looking over logs and Grafana dashboards to see if everything is good. Another week will probably be enough. When no errors come up I will tag the development images as regular ones 🙂

lukassoo commented 7 months ago

No issues have appeared and the docker images have been updated. If any issues appear let me know.

I will also upload a Grafana dashboard and update the readme/wiki - hopefully soon.