Rademacher Homepilot in Home Assistant

however I’m not really keen on investing my free time into that

I understand this. Unfortunately I’m currently techically only able to copa paste and adapt. So I really don’t know what to do. If you know, where such pw protection like here in homepilot has already been used/solved in HA, I would read, try to understand and copy.

Or if anyone else has such or a direct idea here …

Here is how homebridge-plugin is doing this: Link

If a password is that important for your setup I can take a look at it if you want to. Should be easy to do with a commandline sensor and an additional header :slight_smile:

Wow. :+1: This would be more than great. A virtual beer for you in advance. :beer:

So I hacked together a bash script based on the other libraries you’ve posted, it spits out a cookie that can be used to interact with a password-secured homepilot.
However I wasn’t able to replicate the script in Home Assistant (command_line sensor).
If the expiry date on the cookie is correct it shouldn’t expire though, however I think that’s not really true.

If someone has some basic python skills; this should be fairly easy to achieve.

1 Like

Thanks already for the investigation. Hope, that the “little rest” :wink: will work eventually as well.

So, it’s working now, here are the steps:

  • Go into your config folder, create a new file homepilot_cookie.sh
  • Paste this into the newly created file:
######
# Config
password="myPassword!123" # Change this to your password
ip="192.168.x.x" # Change this to the IP of the HomePilot
######
# You shouldn't need to change anything after this line

# Request a salt
saltrequest=$(curl --silent -X POST http://$ip/authentication/password_salt)
#echo "Saltrequest: "$saltrequest

# Extract the salt from JSON.
salt=$(echo -n $saltrequest | jq -r '.password_salt')
#echo "Salt: "$salt

# Calculate sha256 of password
hashedpassword=$(echo -n $password | sha256sum | cut -d " " -f 1)
#echo "Hashed Password: "$hashedpassword

# Concatenate the salt and hashed password
saltedpassword=$salt$hashedpassword
#echo "saltedpassword: "$saltedpassword

# Calculate sha256 of the salt+hashed password
finalpassword=$(echo -n $saltedpassword | sha256sum | cut -d " " -f 1)
#echo "Final Password: "$finalpassword

# Request the cookie
curl --silent --output /dev/null --cookie-jar - --header "Content-Type: application/json" --request POST --data '{"password":"'$finalpassword'","password_salt":"'$salt'"}' http://$ip/authentication/login | tail -n 1| awk '{print $NF}'
  • Create a new sensor:
- platform: command_line
  name: homepilot cookie
  command: "sh /config/homepilot_cookie.sh" 
  scan_interval: 300 # You can increase this, I don't know how long the session is valid, so 5 minutes sounds good
  • Add this to your existing rest commands (belt_winder_up, belt_winder_down,…) and sensors (Cover Dining West Position,…)
    headers: 
      cookie: "HPSESSION={{ states('sensor.homepilot_cookie') }}"

Please report back if and how well that works :slight_smile: I’ll add it to the guide if it does.

More than great. Thanks again for the investigation.

Unfortunately, currently it does’nt work.

I chaged the name of the sensor to homepilot_cookie, to fit to the cookiy states. Right? But neverthelesse, sensor is empty and I think because of this, these are follow up error lines for my three covers

2020-11-25 16:03:34 ERROR (MainThread) [homeassistant.components.template.cover] could not convert string to float: ‘unknown’
2020-11-25 16:03:34 ERROR (MainThread) [homeassistant.components.template.cover] could not convert string to float: ‘unknown’
2020-11-25 16:03:34 ERROR (MainThread) [homeassistant.components.template.cover] could not convert string to float: ‘unknown’

Yeah, had a wrong name in it when posting. What’s the state of sensor.homepilot_cookie?
Anything else in the logs (not the belt winder sensors)?

As mentioned above, the state is always empty. If I fill it manually, after the next run it is empty again. If I execute the script in the terminal line by line I get the results, esp. the last and important one. If I execute the script in total, there is no output. Is this the reason why the sensor is empty (perhaps it is crrently filled by a null output)?

I’ve re-added the cookie sensor from scratch and it’s working fine.
Can you please confirm that:

  • You’ve modified the IP and the password in homepilot_cookie.sh
  • Your password doesn’t include " or ’ (if you can’t avoid it, escape it by changing it to \" and \’)

What does seem to be an issue right now is that the sensors for the position don’t update, seems like they don’t re-try after failing once, I’ll have to take a look at that.

EDIT: Ouch. Looks like you can’t template REST Sensor headers, damn. That means I have to rewrite the sensor as a command_line sensor with curl, should work then.

EDIT 2: Yep, works with a command_line sensor. Instead of a rest sensor for the position, can you please give this a try?

- platform: command_line
  command: 'curl --cookie "HPSESSION={{ states(''sensor.homepilot_cookie'') }}" http://192.168.x.x/devices/2'
  name: 'Cover Dining West Position'
  value_template: '{{ 100 - float(value_json["payload"]["device"]["capabilities"][0]["value"]) }}'
  scan_interval: 20

Yes, everything checked ofter.

Do you have the cookie as output in terminal if you execute sh /config/homepilot_cookie.sh there? As I said, I can only see it, if I execute

curl --silent --output /dev/null --cookie-jar - --header “Content-Type: application/json” --request POST --data ‘{“password”:"’$finalpassword’“,“password_salt”:”‘$salt’"}’ http://$ip/authentication/login | tail -n 1| awk ‘{print $NF}’

but not when running

sh /config/homepilot_cookie.sh

Could that be the reason, why the sensor is always empty? If this would be a problem with PW, IP, etc. I think, then I would get other messages directly from the script, wouldn’t I?

Hm, yeah I can see it, however I see curl output as well, looks like I’ve missed a --silent and the really old cookie I requested a long time ago might still work? :thinking:
Try this for the shell script:

######
# Config
password="password!123" # Change this to your password
ip="192.168.0.0" # Change this to the IP of the HomePilot
######
# You shouldn't need to change anything after this line

# Request a salt
saltrequest=$(curl --silent -X POST http://$ip/authentication/password_salt)
#echo "Saltrequest: "$saltrequest

# Extract the salt from JSON.
salt=$(echo -n $saltrequest | jq -r '.password_salt')
#echo "Salt: "$salt

# Calculate sha256 of password
hashedpassword=$(echo -n $password | sha256sum | cut -d " " -f 1)
#echo "Hashed Password: "$hashedpassword

# Concatenate the salt and hashed password
saltedpassword=$salt$hashedpassword
#echo "saltedpassword: "$saltedpassword

# Calculate sha256 of the salt+hashed password
finalpassword=$(echo -n $saltedpassword | sha256sum | cut -d " " -f 1)
#echo "Final Password: "$finalpassword

# Request the cookie
curl --silent --output /dev/null --cookie-jar - --header "Content-Type: application/json" --request POST --data '{"password":"'$finalpassword'","password_salt":"'$salt'"}' http://$ip/authentication/login | tail -n 1| awk '{print $NF}'

Thought is the other way round. If the print brings out the cookie after executing the command but not with calling the script, perhaps this is the case, why the sensor is not filled.

My Sensor is still with status unknown. Even with the new code.

image

Thought there there sould be seomething like xxxUojgS9ArACPmV7lMxxxxxxxxxxxxxxxxxxxxxxOwSA6n74SjGxxx visible as in the output, of

curl --silent --output /dev/null --cookie-jar - --header “Content-Type: application/json” --request POST --data ‘{“password”:"’$finalpassword’“,“password_salt”:”‘$salt’"}’ http://$ip/authentication/login | tail -n 1| awk ‘{print $NF}’

if I execute it line by line in the terminal.

What is the status of your sensor?

The state should be a long string, like the one you’ve posted.
Do you have the Terminal addon installed and if so, what happens when you execute sh config/homepilot_cookie.sh in it?
My sensor is working fine, updating it gives me a new cookie as well.
You can also run sh -x config/homepilot_cookie.sh to see which commands get executed.
Try setting your password to something simple like password!1 so that special characters won’t cause issues.

1 Like

Hurray. It’s workling now. Whyever this was not the case before. Yes, never change a lot of things at the same time, but now I did. Most probably this was caused by windows end of line in the sh-file. After creating the file again with unix end of line and copy & paste everyhting unchanged, the execution put out the cookie now - even when I run the script and not only the command inside.

image

Then it appears in the sensor. And the status is working as well. Same for the belt_winder commands.

Hi,

thanks for sharing this post. I got it also working :slight_smile: .
Just one thing to improve. For the rest sensor I would suggest to get the current position using a different value_template, which solves the problem that the position of the value is not known in the array.

I implemented it this way:

- platform: rest
  name: 'Wohnzimmer Rechts Position'
  resource: 'http://myip/devices/1'
  value_template: >-
    {% for item in value_json.payload.device.capabilities %}
      {%- if item.name == "CURR_POS_CFG" -%}
        {{ 100 - float(item.value) }}
      {%- endif -%}
    {% endfor %}
  scan_interval: 20
1 Like

Hello Michel, this is absolutely great, no more reconfiguring when upgrading firmware versions :slight_smile:
I’ll update my original post soon.

1 Like

Wollt ihr ein Tutorial für jemanden machen der seit einem Tag Home Assistant nutzt? Habe gehofft Home Assistant erkennt die Rademacher Rolläden automatisch nach dem einbinden in Homebridge :frowning:

Hey Floki,

willkommen bei Home Assistant. Der Guide hier ist zum direkten Einbinden von den Rademacher Basisstationen + Rolläden.
Mit Homebridge / Homekit habe ich keinerlei Erfahrungen, daher kann ich dir dabei leider nicht helfen.
Wenn ich es richtig verstanden habe (sind die Rademacher Homepilots etc. Homekit kompatibel?) sollten die automatisch integriert werden sobald du die Integration in der Konfiguration von Home Assistant eingebunden hast.
Falls das nicht funktioniert kannst du auch der Anleitung hier folgen, das bindet die Rolläden direkt in Home Assistant ein, muss aber manuell gemacht werden. Weiß auch nicht ob die dann in Homekit verfügbar sind, du hast ja dann zwei Hausautomatisierungssysteme nebeneinander laufen :thinking:

Hallo,

ich habe ein ähnliches Problem. Ich habe die sensors.yaml, rest.yaml und cover.yaml wie beschrieben angelegt, aber der state der Rollos wird immer als “open” angezeigt. Folglich kann habe ich nur die Funktion schließen und stoppen zur Verfügung.
Homepilot ist v5.2.23 und DuoFern 2.2

Das angepasste Script für die sensor.yaml führt zum selben Ergebnis. Was kann ich noch tun?