home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.17k stars 29.85k forks source link

myStrom Integration can not connect to new WiFi "Button - Max" buttons #106765

Closed KayGundhardt closed 5 months ago

KayGundhardt commented 8 months ago

The problem

Homassistants myStrom-Integration is not able to connect to a myStrom WiFi Button Max although REST API is integrated in FW Version 1.1.10.

Unsupported myStrom device type: BM1
11:20:52 – (FEHLER) myStrom - Die Nachricht ist zum ersten Mal am 11:14:33 aufgetreten und erscheint 3 mal

What version of Home Assistant Core has the issue?

core-2023.12.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

myStrom

Link to integration documentation on our website

https://www.home-assistant.io/integrations/mystrom

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 8 months ago

Hey there @fabaff, mind taking a look at this issue as it has been labeled with an integration (mystrom) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `mystrom` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign mystrom` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


mystrom documentation mystrom source (message by IssueLinks)

joostlek commented 8 months ago

https://github.com/home-assistant/core/issues/97452#issuecomment-1675972946

KayGundhardt commented 8 months ago

Thank you, @joostlek for your comment: I wasn’t aware that this has been asked already.

Although meanwhile they can connect securely via Token:

IMG_1641

KayGundhardt commented 8 months ago

… and according to the HomeAssitant API docs connecting via token to REST API should be possible:

curl \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  http://IP_ADDRESS:8123/ENDPOINT
joostlek commented 8 months ago

afaik this isn't currently supported by the integration

KayGundhardt commented 8 months ago

You are right, but maybe @fabaff would mind to integrate it…

KayGundhardt commented 8 months ago

🥳

Although not solved I found a workaround for those of you that stumble across this post and try to integrate these buttons.

You can find additional information about:

The Following describes changing an API-POST-Command for Button 1 being pushed once (1x) resulting in turning a HA-entity on. You have of course to repeat the below step 6 for each other command.

  1. Flash the buttons with custom firmware from myStrom themself.
  2. Use the "myStrom Button Max Tool" to connect to the flashed button and configure the button.
  3. Upload the resulting json-File to the button again using the above tool.
  4. Download the json file from the button: curl -s -o configfile.json http://<BUTTON-IP-ADDRESS>/api/v1/config
  5. Edit this file adding the following header repeatedly for each button command: From:
    {
          "http": {
            "method": "POST",
            "payload": " {\"state\": \"on\"}",
            "url": "http://<HA-IP-ADDRESS>/api/states/<HA-ENTITY_ID>"
          },
          "scheme": "1x",
          "trigger": "btn1"
        },

    To:

    {
          "http": {
            "headers":[
              "Authorization: Bearer <LOOOOOONGAPITOKEN>"
            ],
            "method": "POST",
            "payload": " {\"state\": \"on\"}",
            "url": "http://<HA-IP-ADDRESS>/api/states/<HA-ENTITY_ID>"
          },
          "scheme": "1x",
          "trigger": "btn1"
        },
  6. Upload the File again: curl -i -d @configfile.json http://<BUTTON-IP-ADDRESS>/api/v1/config
  7. This should be the buttons answer:
    HTTP/1.1 200 OK
    Content-Type: text/plain
    Content-Length: 0
    Connection: close
    Pragma: no-cache
    Cache-Control: no-store, no-cache
  8. You're DONE :) You can now remotely control HA-Entitys via myStroms WiFi-Button.
fabaff commented 8 months ago

I don't have access to a WiFi Button Max. To be honest I haven't used my WiFi Buttons for while with Home Assistant and I don't know if there were changes in later firmware releases present which would make the integration easier.

The work-around in the past as to use myStrom2MQTT to avoid dealing with tokens.

KayGundhardt commented 8 months ago

Hey @fabaff ! Cool idea: did not finde the MQTT-Capability in myStroms API-Docs: obviously i was completely taken in by the token method ;) How do you manage the API-Command to send the MQTT-Brokers credentials?

joostlek commented 8 months ago

I think it's also interesting to mention that the rest API is unofficially deprecated (afaik). I'd rather use a webhook approach.

KayGundhardt commented 8 months ago

isn't changing the HTTP method from GET to POST and providing the webhook path in the URL enough? You can also define the request body (payload) for a POST/PUT method.

joostlek commented 8 months ago

I'm just giving some hints on how you can improve your setup.

I think we could support setting up webhooks for these buttons as well in the config flow. Except I don't have one of these so I can't really test this or create this.

KayGundhardt commented 8 months ago

Okay, now I understand. Really funny, that you think I could do that! :)) Don’t get me wrong, I am very enthusiastic and really persistent, but I don't have any programming skills: I’m a noob ;)

But if you are willing to write the code, I would be happy to help with the testing and this way give the community something back for all the help. I got myself!

:)

joostlek commented 8 months ago

Not necessarily, you can create a webhook trigger yourself: image

issue-triage-workflows[bot] commented 5 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.