Rademacher Homepilot (DuoFern) via http-Binding

Indeed!
I got it to work as followed based on the script by the HA forum:

#!/bin/bash


######
# Config
password="Test1234!"
bridgeIP="192.168.XXX.XXX"
 command='{"name":"GOTO_POS_CMD","value":"50"}'
######
# You shouldn't need to change anything after this line

# Request a salt
saltrequest=$(curl --silent -X POST --url "http://${bridgeIP}/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
cookie=$(curl --silent --output /dev/null --cookie-jar - --header "Content-Type: application/json" \
    --request POST --data '{"password":"'"${finalpassword}"'","password_salt":"'"${salt}"'"}' \
    --url "http://${bridgeIP}/authentication/login" | \
    tail -n 1 | awk '{print $NF}')
echo "Session Cookie: ${cookie}"


# Send the command to do stuff
curl --cookie "HPSESSION=${cookie}" \
    --request PUT --data "${command}" \
    --url "http://${bridgeIP}/devices/1"

This script will caluclate the cookie and use it to authenticate. Tested it successfully on my rollershutter.


Next step is to check wether it is possible to send this cookie with an sendHttpPutRequest. As far is I can tell from the docs this is not possible. Correct my if I’m wrong.
To bypass this my idea was to set the cookie in a header as follows

val headers = newHashMap("Cookie" -> "HPSESSION=value")

and send it with the request

sendHttpPutRequest(url, "application/x-www-form-urlencoded", command, headers, 1000)

However in contrast to the docs OH complains about the numer of arguments

Rule 'Rolladen': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.HTTP.sendHttpPutRequest(java.lang.String,java.lang.String,java.lang.String,int) on instance: null

TODO:

  • Fix above mentioned error
  • Check on how to receive the data in http.conf. Maybe replace it with the shell script as descriped below
    Now openhab can’t authenticate as I don’t give him any creds
    The cookie expires after a session so we have to check how to get a valid cookie.
  • Implement the script to get the cookie in the rule. As a backup instead of the script returning the cookie and using sendHttpPutRequest in OH we can’t just pass the command to the script and it will run the request

→ All the issues could be dealt with by using one/two simple shell scripts. Does somebody have a besser idea?

1 Like

what is working:

  1. execute script
    ===> cookie (XXXXX as example)
  2. use
    curl -v --cookie “HPSESSION=XXXXX” http://192.168.2.250/v4/devices

gives the list of dids :slight_smile:

probably one would then also use a logout afterwards to prevent to have multiple sessions open, i guess
because the sessions stays up and the cookie valid pretty log.

maybe another idea:
if somebody is able to program a real binding based on the homebrigde plugin all will be already existing.
im not a programmer so this idea may be naive :slight_smile:

if somebody is able to program a real binding based on the homebrigde plugin all will be already existing.

Add it to my to-do list. Just have to find time to do it lol… (will not happen soon)

This is my working configuration of an rollershutter with a password set:

Scripts to get and set the state

┌─[17:31:07]-[:)]-[openhabian@openhab]-[/etc/openhab2/scripts/Rolladen/ (master)]
└──> ll
insgesamt 12K
-rw-r--r-- 1 openhabian openhabian 1,2K 17:28 23.05.2022 getCookie.sh
-rw-r--r-- 1 openhabian openhabian  463 17:28 23.05.2022 getState.sh
-rw-r--r-- 1 openhabian openhabian  544 17:28 23.05.2022 setState.sh

┌─[17:31:15]-[:)]-[openhabian@openhab]-[/etc/openhab2/scripts/Rolladen/ (master)]
└──> cat getCookie.sh
#!/bin/bash

readonly password="xxx"
readonly bridgeIP="${1}"

# Request a salt
saltRequest=$(curl --silent -X POST --url "http://${bridgeIP}/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
cookie=$(curl --silent --output /dev/null --cookie-jar - --header "Content-Type: application/json" \
    --request POST --data '{"password":"'"${finalPassword}"'","password_salt":"'"${salt}"'"}' \
    --url "http://${bridgeIP}/authentication/login" | \
    tail -n 1 | awk '{print $NF}')
# echo "Session Cookie: ${cookie}"
echo "${cookie}"
┌─[17:31:18]-[:)]-[openhabian@openhab]-[/etc/openhab2/scripts/Rolladen/ (master)]
└──> cat getState.sh
#!/bin/bash

# shellcheck disable=1091
source /etc/openhab2/scripts/RPi4/send.sh

readonly bridgeIP="xxx"
# shellcheck disable=2155
  readonly cookie=$(/bin/bash /etc/openhab2/scripts/Rolladen/getCookie.sh "${bridgeIP}")
[[ -z "${cookie}" ]] && exit 1


raw_state=$(curl --cookie "HPSESSION=${cookie}" --url "http://${bridgeIP}/v4/devices" 2>/dev/null)

send "Verdunklung_Rolladen" "$(echo "${raw_state}" | jq '."devices"[0]."statusesMap"."Position"')"
┌─[17:32:48]-[:(]-[openhabian@openhab]-[/etc/openhab2/scripts/Rolladen/ (master)]
└──> cat /etc/openhab2/scripts/RPi4/send.sh
#!/bin/bash

send(){
    OHIP="localhost"
    curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "${2}" "http://${OHIP}:8080/rest/items/${1}/state"
}
┌─[17:31:22]-[:)]-[openhabian@openhab]-[/etc/openhab2/scripts/Rolladen/ (master)]
└──> cat setState.sh
#!/bin/bash

readonly bridgeIP="xxx"
# shellcheck disable=2155
  readonly cookie=$(/bin/bash /etc/openhab2/scripts/Rolladen/getCookie.sh "${bridgeIP}")
[[ -z "${cookie}" ]] && exit 1
 readonly command="${1}"


echo curl --cookie "HPSESSION=${cookie}" \
    --request PUT --data "${command}" \
    --url "http://${bridgeIP}/devices/1" >> /tmp/test2

# Send the command to the bridge
curl --cookie "HPSESSION=${cookie}" --request PUT --data "${command}" --url "http://${bridgeIP}/devices/1"

Cronjob to call the getter every 5 minutes

rule "Alle 5 Minuten: Rolladen Status abrufen"
when
    Time cron "0 */5 * * * ?"
then
    executeCommandLine("/etc/openhab2/scripts/Rolladen/getState.sh")
end
2 Likes

Is there anybody who know the http command for ventilation ? I tried sun but I guess that the ventilation is another cmd.

many thanks
Chris

Hello and thank you for the great work you all did to control the Rademacher components via Openhab and query sensors!

I have another question regarding Homepilot groups.

Is there a possibility, for example, to address the roller shutter groups instead of the individual roller shutters via DID?

Hi Rademacher-Users,
openHAB 4.0 is on its way and a first milestone version is available and can be tested.

I would like to make you aware that our existing config will not work anymore with that new openHAB version because the JS transformation will no longer exists. The SCRIPT transformation should be used instead.

@danil and all others - do you see a chance to review your RollerShutterPositionJSON.js ?
Can this be realized with SCRIPT transformation as well?

I am looking forward to get Rademacher stuff working (again) in openHAB 4.x :slight_smile:

Kai

Hi Kai,
yes, I can confirm SCRIPT Transformation is working too.

Renamed RollershutterPositionJSON.js to RollershutterPositionJSON.script
Changed commandTransformation: JS:RollerShutterPositionJSON.js to commandTransformation: SCRIPT:js:RollershutterPositionJSON.script

Edit: Tested with openHAB 3.4.2

Hi,
thank you for your post. With your code I was able to connect my homepilot to my openhab3 system. Unfortunately I am very much of a rooky but I have the will to learn. Maybe you can give me a hint with my problem I have right now.
I can control my rollershutter and switches, everything works perfectly but what I cannot get working is the Status of my switches. For example I switch on my living room light with the homepilot app but the openhab client won’t show me that the light is switched on. When I look at http://192.168.xxx.xxx/v4/devices?devtype=switch I can see my switch and that there is a change at “statusesMap: position”. If the switch is off it will show “0” and if it is on the value is “100”. How do I configure openhab that way that it checks this value and refreshes the gui. Thank you very much in advance for your support.

Hi @Skywalker / Marc,
I just tested this with my Rademacher Switch. I am using that plug with my hood in the kitchen and status is available in my openHAB.
When using Rademacher HomePilot GUI I can see in OH log:

 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AbzugshaubeStatus' changed from 0 to 100
 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AbzugshaubeStatus' changed from 100 to 0

Did you add the transformation to the .things?
My plug is called “Kueche_Abzugshaube” (=Kitchen_Hood)
My config files:
.things:

Type switch : Kueche_Abzugshaube [
            mode="WRITEONLY",
            commandExtension="/devices/27",
            onValue="{\"name\":\"TURN_ON_CMD\"}",
            offValue="{\"name\":\"TURN_OFF_CMD\"}"
        ]
Type number : Kueche_Abzugshaube#Status [
            stateExtension="/v4/devices/27",
            stateTransformation="JSONPATH:$.device.statusesMap.Position",
            commandTransformation="JS:RollerShutterPositionJSON.js",
            commandExtension="/devices/27"
        ]

And .items file:

Switch        Abzugshaube    	        "Abzugshaube  [%s]"            {homekit="Switchable", alexa="Switch", channel="http:url:HomePilot1:Kueche_Abzugshaube"} 
Number        AbzugshaubeStatus        	"Abzugshaube, Status [%d %%]"  {channel="http:url:HomePilot1:Kueche_Abzugshaube#Status"}

Many thanks for your support. Of course it works directly. I am on my way to have a lucky wife :wink:

1 Like

happy wife, happy life :rofl:

Hi,
I am back again ;-). How can I add an item (e.g. a switch or shutter) to a location, or maybe to two location in item file? I have searched a bit on the openhab manual and found out that it is quite simple to add an item to a group. for example (Wohnzimmer). ```
Example from manual:
String Bedroom_Sonos_CurrentTitle “Title [%s]” (gBedRoom) {channel=“sonos:…”}
In this case (gBedRoom) ist the group.
I did not found any notice for doing this procedure for locations. I have tried it then via MAINUI in the “model” section. I created some locations and then I have tried to link my item (eg Wohnzimmer_Wohnwand (switch) to the location Wohnzimmer but of course it did not work.
All items that are added manually by items.file are locked and cannot be modified by MAINUI. Is there any chance to solve this problem or do you have any idea where I can read more about this.
Many thanks for your help again…
Greetings,
Marc

Hi @Skywalker,
I do not use locations - I cannot comment on this.

How about using rules?
Maybe you can build your scenario with rules: “if someting happens THEN execute a Radmacher-command”.
This is how I do it for all my automations.
regards, Kai

Hi @danil,
today openHAB 4 was released…
While everything still was working in Milesstone1 and 2 now I am unable to get it running again.
Did you had a chance to test this (again)?
I renamed the commands accordingly and there is not even an error or something else in the log.
Shutters are not moving to target position anymore.
The script RollerShutterPositionJSON.script does not need any changes, right?
regards, Kai

After the upgrade to OH4 I still run into the problem the the translation script RollerShutterPositionJSON.js doesn’t work anymore.

Get the error

Transformation service JS for pattern RollerShutterPositionJSON.js not found!

The file ist there. In other topics I found out that it’s a syntax problem but not sure. Another thing can be the hint in the upgrade routine :

ORE: Rules are now triggered by ItemStateUpdatedEvent instead of ItemStateEvent. If you use JSR223 scripting without helper libraries and expect a certain Java type, code changes might be needed.

This is used by the RAdemacher integration. I use the helper libraries so I guess I don’t must do anything.

Actual I have no clue what the problem is and no idea where to search.

Would be great if someone has an idea.
Christian

please ignore. See comment from Udo below.

please see advice from danil.
You need to rename some stuff:
Rename RollershutterPositionJSON.js to RollershutterPositionJSON.script
Change commandTransformation: JS:RollerShutterPositionJSON.js to commandTransformation: SCRIPT:js:RollershutterPositionJSON.script

No, please don’t, this information is outdated!

openHAB4 Milestones used SCRIPT Transformation instead of JS to enable more than JS.
BUT: in openHAB1 (and all following versions) there was and is already the .script file extension.
So, there was another change for the better.

You can now simply use JS and the file extension .js and other scripts as well. But there is no JS transformation any longer, you have to install JavaScript Scripting instead, which will take care of the JS Transformation.

2 Likes

Thank you @Udo_Hartmann for that valuable information.
I installed JavaScript Scripting and the previous config is working again! :heart_eyes:

e.g. things file:

Type number : Room_1 [
            stateExtension="/v4/devices/24",
            stateTransformation="JSONPATH:$.device.statusesMap.Position",
            commandTransformation="JS:RollerShutterPositionJSON.js",
            commandExtension="/devices/24"