IngmarStein / mielesolar

Trigger Miele SmartStart with SolarEdge inverters
MIT License
9 stars 0 forks source link

Cannot run this program, help is appreciated #8

Closed requiemmg closed 1 year ago

requiemmg commented 1 year ago

Hi,

this is exactly what I am looking for. I have a SmartGrid enabled tumbler and washing machine and a SolarEdge inverter.

Now I'd like to make use of smartStart. I have not found a solution for home assistant.

Unfortunately, I am no too much into programming and your instructions failed me.

I try to run this on a Raspi 3B.

First I tried "go get" which told me that "get" was deprecated and I should use "install" instead. Did so, but calling the package failed with "is not in GOROOT folder".

Second I tried docker run, which gave me

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm/v7) and no specific platform was requested
exec /mielesolar: exec format error

I'd really appreciate help in running this. Further, can I start it up automatically on the raspi's reboot?

Thanks for your time.

requiemmg commented 1 year ago

Okay,

now I have it installed (git clone, move to $GOROOT, go get, go build), but the parameters seem to be wrong. I have set up a config file (devices.json) and call the program but I get a "user/pass wrong" - I copypasted them from another project which uses the API and which is currently up and running...so it must be the syntax. The syntax differs which the program expects differs from the example in the readme.md. Tried both, but there must be sth wrong. Can you please tell me how to properly make a call?

/usr/local/go/src/mielesolar/mielesolar -user my@email.com -password SuperSecret -client-id "abc3434-3473842-sthlikethat" -client-secret "bunCHofLetters" mielesolar -inverter 192.168.0.170 -port 502 -vg de-DE -config
2023/01/17 17:24:27 error retrieving Miele token: oauth2: cannot fetch token: 401 Unauthorized
Response: {"message":"username/password is invalid"}
pi@RaspberryPi:/usr/local/go/src/mielesolar $

Tried with and without "" at different places....

IngmarStein commented 1 year ago

Sorry, I missed the GitHub notification!

First, I've updated the installation instructions to use go install which was introduced in Go 1.17. Thanks for mentioning that.

Second, the format of the client ID (8-4-4-4-12 characters) and secret (32 characters) look correct. Your example command line has a stray mielesolar between the -client-secret and -inverter arguments. Was this just a copy & paste error?

requiemmg commented 1 year ago

Thanks for your reply and nevermind the missed notification!

In fact, the additional mielesolar was copied from the installation instructions and its still there.

Noticed already but I always get the failure that my credentials are wrong - while they run fine in another project (and no matter if this is running or not) MMM-Miele for MagicMirror.

I tried with and without " or '.

Would really appreciate help. And maybe you can add instructions on how to run it as a system service on a pi?

Sorry, I have not that much programming experience and none at go....thanks a lot for your work!

IngmarStein commented 1 year ago

The example command line in https://github.com/IngmarStein/mielesolar#3-run-mielesolar is slightly different: it passes credentials through environment variables instead of command line arguments (so that they're not visible in the process list). Maybe you can try that and check whether the environment variables contain the expected values and no special characters are interpreted by your shell?

I'm running mielesolar natively on a Synology NAS and used to run it in a Docker container before that, so those two paths are tested. I don't have a Raspi around to test a system service, but instructions for that would be a welcome contribution.

requiemmg commented 1 year ago

Yup, I got thru that, and I think there is some problem with the command line options. Just to be sure, I requested new credentials but Miele seems to process them manually. As my current one's work, I think it's either a problem with my syntax, with the interpretation of my syntax or maybe a bug in the code. Anyway, I am highly interested in sorting this one out.

Docker build is not for Raspi and I do not own a Synology NAS.

And sorry, I do not know how to check env variables from bash on my raspi for a specific program which runs from the command line.

What I noticed today: I just started mielesolar with user/pass/client/secret, this was already sufficient to get a 401: user/pass invorrect error :-(

./mielesolar -user 'mymail@gmail.com' -password 'password' -client-secret '12345' -client-id '91253'
2023/01/18 23:14:02 error retrieving Miele token: oauth2: cannot fetch token: 401 Unauthorized
Response: {"message":"username/password is invalid"}

(of course, my credentials have been changed, but this is what happens when I use the correct credentials). I think, first I have to go beyond this point.

I don't know what to try anymore. If you want I'll contact you on LinkedIn and we can find a way you can try it out on my raspi?

IngmarStein commented 1 year ago

Your client ID + client secret seem valid. If they were not, you'd get Client credentials are not valid instead of username/password is invalid.

The country selector is important - it's a necessary part for authentication. The default is de-CH (as a convenience for me), so you need to pass the location in which your account is registered, for example -vg de-DE.

Btw, the Raspberry Pi can run Docker (https://www.simplilearn.com/tutorials/docker-tutorial/raspberry-pi-docker), but a native solution may be preferred.

requiemmg commented 1 year ago

About docker: On a raspi, I will get an error that it is a wrong platform...

BUT...we are getting closer. Now providing -vg de-DE will authenticate correctly. Specifying the inverter's IP also works. Verbose also works. But specifying either -auto or a config file will just throw the help text. But we are getting closer.

Next step after running it from shell: running it as a service from startup. Corrently, I need to be in the programs directory.... (/usr/local/go/src/mielesolar)

Current status:


pi@RaspberryPi:/usr/local/go/src/mielesolar $ ./mielesolar -user 'user' -password 'password' -client-secret 'secret' -client-id 'id' -vg de-DE -verbose -
inverter 192.168.0.170
2023/01/19 00:17:28 Inverter Model: SE9K-RW0TEBEN4
2023/01/19 00:17:28 Inverter Serial: 7E1D3AE5
2023/01/19 00:17:28 Inverter Version: 0004.0017.0046
2023/01/19 00:17:28 Meter Manufacturer: SolarEdge
2023/01/19 00:17:28 Meter Model: SE-MTR-3Y-400V-A
2023/01/19 00:17:28 Meter Serial: 606848072
2023/01/19 00:17:28 Meter Version: 78
2023/01/19 00:17:28 Meter Option: Export+Import
2023/01/19 00:17:33 starting refresh
2023/01/19 00:17:33 GET /v1/devices/000150786902/state HTTP/1.1
Host: api.mcs3.miele.com
Accept: application/json
User-Agent: go-miele

2023/01/19 00:17:34 HTTP/2.0 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization
Access-Control-Allow-Methods: PUT, GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 1728000
Content-Type: application/json
Date: Wed, 18 Jan 2023 23:17:33 GMT
Strict-Transport-Security: max-age=15724800; includeSubDomains
Vary: Accept-Encoding
X-Environment: mcs-eu-prod-std
X-Environment: mcs-eu-prod-default

{"ProgramID":{"value_raw":0,"value_localized":"","key_localized":"Program name"},"status":{"value_raw":1,"value_localized":"Off","key_localized":"status"},"programType":{"value_raw":0,"value_localized":"Program","key_localized":"Program type"},"programPhase":{"value_raw":0,"value_localized":"","key_localized":"Program phase"},"remainingTime":[0,0],"startTime":[0,0],"targetTemperature":[{"value_raw":-32768,"value_localized":null,"unit":"Celsius"},{"value_raw":-32768,"value_localized":null,"unit":"Celsius"},{"value_raw":-32768,"value_localized":null,"unit":"Celsius"}],"coreTargetTemperature":[{"value_raw":-32768,"value_localized":null,"unit":"Celsius"}],"temperature":[{"value_raw":-32768,"value_localized":null,"unit":"Celsius"},{"value_raw":-32768,"value_localized":null,"unit":"Celsius"},{"value_raw":-32768,"value_localized":null,"unit":"Celsius"}],"coreTemperature":[{"value_raw":-32768,"value_localized":null,"unit":"Celsius"}],"signalInfo":false,"signalFailure":false,"signalDoor":true,"remoteEnable":{"fullRemoteControl":true,"smartGrid":true,"mobileStart":false},"ambientLight":null,"light":null,"elapsedTime":[0,0],"spinningSpeed":{"unit":"rpm","value_raw":null,"value_localized":null,"key_localized":"Spin speed"},"dryingStep":{"value_raw":null,"value_localized":"","key_localized":"Drying level"},"ventilationStep":{"value_raw":null,"value_localized":"","key_localized":"Fan level"},"plateStep":[],"ecoFeedback":null,"batteryLevel":null}
2023/01/19 00:17:34 GET /v1/devices/000177217968/state HTTP/1.1
Host: api.mcs3.miele.com
Accept: application/json
User-Agent: go-miele
requiemmg commented 1 year ago

Update: WORKS now from the command line (I forgot to specify an int value for "auto", but as I have 4 Miele Devices I will need to think how I will priorize them in a config file). Now I need to find out how to run in automatically on startup..

Thanks for your help! (I think the missing -vg de-DE was the problem when I finally could compile the program)

requiemmg commented 1 year ago

I think this looks fine now :-)

pi@RaspberryPi:~ $ sudo systemctl status mielesolar
● mielesolar.service - Mielesolar
     Loaded: loaded (/lib/systemd/system/mielesolar.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-01-19 10:59:08 CET; 3min 41s ago
   Main PID: 1357 (mielesolar)
      Tasks: 7 (limit: 2058)
        CPU: 624ms
     CGroup: /system.slice/mielesolar.service
             └─1357 /usr/local/go/src/mielesolar/mielesolar -user user -password password -c>

Jan 19 10:59:08 RaspberryPi systemd[1]: Started Mielesolar.
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 2023/01/19 10:59:09 Inverter Model: SE9K-RW0TEBEN4
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 2023/01/19 10:59:09 Inverter Serial: 7E1D3AE5
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 2023/01/19 10:59:09 Inverter Version:
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 0004.0017.0046
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 2023/01/19 10:59:09 Meter Manufacturer: SolarEdge
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 2023/01/19 10:59:09 Meter Model: SE-RGMTR-1D-240C-A
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 2023/01/19 10:59:09 Meter Serial: 0
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 2023/01/19 10:59:09 Meter Version: 0
Jan 19 10:59:09 RaspberryPi mielesolar[1357]: 2023/01/19 10:59:09 Meter Option: Export+Import
Setcover commented 1 year ago

Btw, the Raspberry Pi can run Docker (https://www.simplilearn.com/tutorials/docker-tutorial/raspberry-pi-docker), but a native solution may be preferred.

Problem: I wouldn't expect your docker-image to run on a raspberry pi, as it is not (cross)compiled for arm/v7 (v6/v5/64v8) architecture, see https://hub.docker.com/r/ingmarstein/mielesolar/tags

Would you consider crosscompiling it? e.g. using docker buildx https://docs.docker.com/build/building/multi-platform/

Or add instructions on how to compile it oneself.

git clone https://github.com/IngmarStein/mielesolar.git
cd mielesolar/
sudo docker build -t mielesolar:v1 .
# modify docker-compose.yml to use selfbuild image
sed -i 's,ingmarstein/mielesolar:latest,mielesolar:v1,g' docker-compose.yml
# confirm everything went fine up to this point
sudo docker-compose up
# add credentials (save and quit with CTRL + X, confirm with Y)
nano docker-compose.yml
# test (quit using CTRL + C)
sudo docker-compose up
# run as background service (daemon mode)
sudo docker-compose up -d

At least for my raspberry pi 4 (arm v7) it looked like everything went smooth. Unfortunately i have no miele devices to test it.

pi@octopi5:~ $ sudo rm -r mielesolar/
rm: cannot remove 'mielesolar/': No such file or directory
pi@octopi5:~ $ sudo docker container ls
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
pi@octopi5:~ $ sudo docker image ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
pi@octopi5:~ $ git clone https://github.com/IngmarStein/mielesolar.git
Cloning into 'mielesolar'...
remote: Enumerating objects: 526, done.
remote: Counting objects: 100% (113/113), done.
remote: Compressing objects: 100% (80/80), done.
remote: Total 526 (delta 69), reused 63 (delta 33), pack-reused 413
Receiving objects: 100% (526/526), 152.66 KiB | 3.05 MiB/s, done.
Resolving deltas: 100% (337/337), done.
pi@octopi5:~ $ cd mielesolar/
pi@octopi5:~/mielesolar $ sudo docker build -t mielesolar:v1 .
Sending build context to Docker daemon  351.2kB
Step 1/8 : FROM golang:1.19.5-alpine AS builder
1.19.5-alpine: Pulling from library/golang
c527615e4ffa: Pull complete
90c7609f223a: Pull complete
da97c3a81e19: Pull complete
64e98750b6aa: Pull complete
Digest: sha256:2381c1e5f8350a901597d633b2e517775eeac7a6682be39225a93b22cfd0f8bb
Status: Downloaded newer image for golang:1.19.5-alpine
 ---> 348b24e92c8a
Step 2/8 : WORKDIR /go/src/github.com/ingmarstein/mielesolar/
 ---> Running in 05d24e6de998
Removing intermediate container 05d24e6de998
 ---> 04a380cb41ef
Step 3/8 : COPY . .
 ---> ac6912be2b41
Step 4/8 : RUN apk add -U --no-cache ca-certificates git  && CGO_ENABLED=0 GOOS=linux go build .
 ---> Running in 7b474e66c8b9
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/armv7/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/armv7/APKINDEX.tar.gz
(1/7) Installing brotli-libs (1.0.9-r9)
(2/7) Installing nghttp2-libs (1.51.0-r0)
(3/7) Installing libcurl (7.87.0-r1)
(4/7) Installing libgcc (12.2.1_git20220924-r4)
(5/7) Installing libexpat (2.5.0-r0)
(6/7) Installing pcre2 (10.42-r0)
(7/7) Installing git (2.38.3-r1)
Executing busybox-1.35.0-r29.trigger
OK: 12 MiB in 23 packages
go: downloading github.com/goburrow/modbus v0.1.0
go: downloading github.com/ingmarstein/miele-go v0.0.0-20221005183253-e7bbdc188dad
go: downloading github.com/goburrow/serial v0.1.0
go: downloading github.com/google/go-querystring v1.1.0
go: downloading golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
go: downloading golang.org/x/net v0.0.0-20201024042810-be3efd7ff127
Removing intermediate container 7b474e66c8b9
 ---> 8288f57d244c
Step 5/8 : FROM scratch
 --->
Step 6/8 : COPY --from=builder /go/src/github.com/ingmarstein/mielesolar/mielesolar /mielesolar
 ---> 421e64d6728d
Step 7/8 : COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
 ---> 6030bc3a0f8f
Step 8/8 : ENTRYPOINT ["/mielesolar"]
 ---> Running in 82ceeea5f0d9
Removing intermediate container 82ceeea5f0d9
 ---> 016c13c8976c
Successfully built 016c13c8976c
Successfully tagged mielesolar:v1
pi@octopi5:~/mielesolar $ sed -i 's,ingmarstein/mielesolar:latest,mielesolar:v1,g' docker-compose.yml
pi@octopi5:~/mielesolar $ sudo docker-compose up
Creating network "mielesolar_default" with the default driver
Creating mielesolar_mielesolar_1 ... done
Attaching to mielesolar_mielesolar_1
mielesolar_1  | Usage of /mielesolar:
mielesolar_1  |   -auto int
mielesolar_1  |         automatically start waiting devices if a minimum amount of power is available
mielesolar_1  |   -client-id string
mielesolar_1  |         Miele 3rd Party API client ID
mielesolar_1  |   -client-secret string
mielesolar_1  |         Miele 3rd Party API client secret
mielesolar_1  |   -config string
mielesolar_1  |         Device config file (default "devices.json")
mielesolar_1  |   -interval int
mielesolar_1  |         Polling interval in seconds (default 5)
mielesolar_1  |   -inverter string
mielesolar_1  |         Inverter address or IP (default "192.168.188.167")
mielesolar_1  |   -password string
mielesolar_1  |         Miele@Home password
mielesolar_1  |   -port int
mielesolar_1  |         MODBUS over TCP port (default 502)
mielesolar_1  |   -user string
mielesolar_1  |         Miele@Home user name
mielesolar_1  |   -verbose
mielesolar_1  |         verbose mode
mielesolar_1  |   -vg string
mielesolar_1  |         country selector (default "de-CH")
pi@octopi5:~/mielesolar $ uname -m
armv7l
IngmarStein commented 1 year ago

@requiemmg well done and welcome user number 2 :) Looks like you're up and running now. Let me know if you managed to get a smart start triggered. It would be a great addition to build a Debian Package for Raspian and host that somewhere.

@Setcover you're right the image is currently only available for linux/amd64. Shouldn't be a big deal to cross-compile it for armv7. I might have a look over the weekend.

requiemmg commented 1 year ago

Sure thing, I'll let you know. Today snow on my panels, so no solar power ☀️

IngmarStein commented 1 year ago

@Setcover the armv7 image is up (https://hub.docker.com/r/ingmarstein/mielesolar/tags).

Setcover commented 1 year ago

looks good to me 👍 (again, neither miele device nor solar inverter to test)

pi@octopi5:~ $ sudo rm -r mielesolar/
pi@octopi5:~ $ sudo docker container ls; sudo docker image ls; sudo docker system prune -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated to them
  - all build cache

Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
pi@octopi5:~ $ mkdir mielesolar && cd mielesolar && wget https://raw.githubusercontent.com/IngmarStein/mielesolar/main/docker-compose.yml
--2023-01-19 15:51:38--  https://raw.githubusercontent.com/IngmarStein/mielesolar/main/docker-compose.yml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 355 [text/plain]
Saving to: ‘docker-compose.yml’

docker-compose.yml                                   100%[=====================================================================================================================>]     355  --.-KB/s    in 0s

2023-01-19 15:51:39 (5.74 MB/s) - ‘docker-compose.yml’ saved [355/355]

pi@octopi5:~/mielesolar $ sudo docker-compose up
Creating network "mielesolar_default" with the default driver
Pulling mielesolar (ingmarstein/mielesolar:latest)...
latest: Pulling from ingmarstein/mielesolar
e391339e158c: Pull complete
9806ea516711: Pull complete
Digest: sha256:ee87b62a7a77f3980c62bc487b56dd3a5431f26522bd1400d1d558b3694c277f
Status: Downloaded newer image for ingmarstein/mielesolar:latest
Creating mielesolar_mielesolar_1 ... done
Attaching to mielesolar_mielesolar_1
mielesolar_1  | Usage of /mielesolar:
mielesolar_1  |   -auto int
mielesolar_1  |         automatically start waiting devices if a minimum amount of power is available
mielesolar_1  |   -client-id string
mielesolar_1  |         Miele 3rd Party API client ID
mielesolar_1  |   -client-secret string
mielesolar_1  |         Miele 3rd Party API client secret
mielesolar_1  |   -config string
mielesolar_1  |         Device config file (default "devices.json")
mielesolar_1  |   -interval int
mielesolar_1  |         Polling interval in seconds (default 5)
mielesolar_1  |   -inverter string
mielesolar_1  |         Inverter address or IP (default "192.168.188.167")
mielesolar_1  |   -password string
mielesolar_1  |         Miele@Home password
mielesolar_1  |   -port int
mielesolar_1  |         MODBUS over TCP port (default 502)
mielesolar_1  |   -user string
mielesolar_1  |         Miele@Home user name
mielesolar_1  |   -verbose
mielesolar_1  |         verbose mode
mielesolar_1  |   -vg string
mielesolar_1  |         country selector (default "de-CH")
pi@octopi5:~/mielesolar $
IngmarStein commented 1 year ago

I'll close this for now as the original problem "cannot run this program" is solved. Feel free to create new issues when other things pop up.