I’m trying to use the MyStrom buttons, and these work through an API call back to home assistant. I’m struggling with the authentication. I have an API password set:
However when I try to test the API with curl, I get 401 unauthorized:
$ curl -X GET -k "https://walker:8123/api/mystrom?api_password=##########&single=myStromButton01"
401: Unauthorized
I can get it working with a header and a bearer token:
$ curl -X GET -k -H 'Authorization: Bearer <LongToken>' "https://walker:8123/api/mystrom?single=myStromButton01"
however I don’t know how I can put a header into the MyStrom button config (I seem to only be able to program this with the URL (and the docs say to put api_password=##### into the URL, which is not working. The button (and the computer I was running curl from) are in the trusted network ranges.
Is there a way I can allow the switches to work without the token (using either api-password or by exempting them from authorisation?
Hi all,
I’m quite satisfied using myStrom wifi button with HA webhooks.
It’s natively available, no add-ons are needed and perfectly solve the API password issue.
I configured different request for any action on wifi button:
curl --location --request POST 'http://192.168.202.155/api/v1/action/single' \
--data-raw 'post://192.168.202.151:8123/api/webhook/mystrom_b1?action=single'
curl --location --request POST 'http://192.168.202.155/api/v1/action/double' \
--data-raw 'post://192.168.202.151:8123/api/webhook/mystrom_b1?action=double'
curl --location --request POST 'http://192.168.202.155/api/v1/action/generic' \
--data-raw 'post://192.168.202.151:8123/api/webhook/mystrom_b1?action=generic'
so I can manage them from HA.
I can see POST requests coming from myStrom button:
Hi @rosseba, exactly same issue with standard call (get + login error). I will try your solution.
I would be happy to see if you get any response with your question of URL parameters for conditional actions. Kind regards,
Romain
A brief update:
using input_number I’m tracking button battery, below the config I’m using.
myStrom button trigger generic request (with battery status as well) every 12h-ish.
Since every message normally contains the battery level, there is a second action in the automation which checks whether battery is present. If yes, the corresponding input_number is updated with the current battery level.
I am struggling with this part. how can I check if the button has received this coding correctly? It shows after clicking first white, then green, then a red light. In HA it seems that the request comes not through. Via postman I can trigger the hook.
Can I maybe set the URL in the app?
Via curl this comes back from the button for the coding:
Is this what you sent before? If yes, then from the MyStrom button point of view, it should be fine.
Do you have a possibility to run a tcpdump or wireshark to check whether your homeassistant receives the message? Your homeassistant runs on port 443 or 80? In my case, homeassistant runs on port 8123 in plain mode. I’m using a reverse proxy in front of it to encrypt the traffic. I’m not sure if the MyStrom Buttons support TLS…
I found it!
I used a domain which did not work properly. For this use case I guess it is fine to directly point to a IP. Still wondering why it did not work correctly. Maybe my reverse proxy need some tweaks.
My final solution attached with the addon to toggle per button function a boolean. Is there room for improvement? Can I somehow aggregate code to make it cleaner?
config
input_boolean:
button1_short_pressed:
name: button1_short_pressed
initial: off
button1_long_pressed:
name: button1_long_pressed
initial: off
button1_double_pressed:
name: button1_double_pressed
initial: off