Cloud-based Miele@home to MQTT

Tags: #<Tag:0x00007f7455dafae0>

Hello!

I have written a script to retrieve data from Miele@home WiFi (the cloud-based service, without a gateway at home).

It is based on the beta-API from Miele. Personally, I run it from OpenHab through the “Execute” binding, and have it run every 30 seconds. I don’t really use any output from the script, but rather use the script to send MQTT messages. This was to make it more universal, so it could be useful even if you run other home automation systems. It could just as well be run through cron, if one prefers, but for now, it only works in Linux.

Since I only have a dishwasher from Miele, currently, only dishwasher has been implemented. Therefore, I have included a “-d” option, which means “dump data”. So, to add support for more device types, run the script with the parameter “-d” while your appliance is ON, and capture the output of the script. From there on, you (or I) could add your new device type into the final block of code in the script.

I would like to create a true OH binding based on this, but need to find time to learn how to write bindings, and how to code java first, which might take several months (that is to find time, not to learn) :wink:

If anyone is interested, you can check out the script here: https://github.com/oklona/Miele-MQTT

7 Likes

Hi Ole,

I captured the output of my washing machine and I found following code. Particularly interesting would be the power level I think.
How can I add it to the script? Or will the message appear once the machine is actually running(currently off)

Also you should add a configuration item for username and password of the mosquitto server. added those manually in the script after completing the initial configuration

edit:
actually I believe those items are not supported and therefore not included in the server message. just read the api docs.

still great script

array(1) {
  ["000149210963"]=>
  array(2) {
    ["ident"]=>
    array(4) {
      ["type"]=>
      array(3) {
        ["key_localized"]=>
        string(10) "Devicetype"
        ["value_raw"]=>
        int(1)
        ["value_localized"]=>
        string(15) "Washing Machine"
      }
      ["deviceName"]=>
      string(0) ""
      ["deviceIdentLabel"]=>
      array(5) {
        ["fabNumber"]=>
        string(12) "000149210963"
        ["fabIndex"]=>
        string(2) "11"
        ["techType"]=>
        string(6) "WWE660"
        ["matNumber"]=>
        string(8) "10691910"
        ["swids"]=>
        array(6) {
          [0]=>
          string(4) "4418"
          [1]=>
          string(5) "20456"
          [2]=>
          string(5) "25213"
          [3]=>
          string(4) "4418"
          [4]=>
          string(5) "20456"
          [5]=>
          string(5) "25213"
        }
      }
      ["xkmIdentLabel"]=>
      array(2) {
        ["techType"]=>
        string(5) "EK037"
        ["releaseVersion"]=>
        string(5) "03.58"
      }
    }
    ["state"]=>
    array(16) {
      ["status"]=>
      array(3) {
        ["value_raw"]=>
        int(1)
        ["value_localized"]=>
        string(3) "Off"
        ["key_localized"]=>
        string(5) "State"
      }
      ["programType"]=>
      array(3) {
        ["value_raw"]=>
        int(1)
        ["value_localized"]=>
        string(7) "Cottons"
        ["key_localized"]=>
        string(9) "Programme"
      }
      ["programPhase"]=>
      array(3) {
        ["value_raw"]=>
        int(268)
        ["value_localized"]=>
        string(0) ""
        ["key_localized"]=>
        string(5) "Phase"
      }
      ["remainingTime"]=>
      array(2) {
        [0]=>
        int(0)
        [1]=>
        int(0)
      }
      ["startTime"]=>
      array(2) {
        [0]=>
        int(0)
        [1]=>
        int(0)
      }
      ["targetTemperature"]=>
      array(3) {
        [0]=>
        array(3) {
          ["value_raw"]=>
          int(4000)
          ["value_localized"]=>
          float(40)
          ["unit"]=>
          string(7) "Celsius"
        }
        [1]=>
        array(3) {
          ["value_raw"]=>
          int(-32768)
          ["value_localized"]=>
          NULL
          ["unit"]=>
          string(7) "Celsius"
        }
        [2]=>
        array(3) {
          ["value_raw"]=>
          int(-32768)
          ["value_localized"]=>
          NULL
          ["unit"]=>
          string(7) "Celsius"
        }
      }
      ["temperature"]=>
      array(3) {
        [0]=>
        array(3) {
          ["value_raw"]=>
          int(-32768)
          ["value_localized"]=>
          NULL
          ["unit"]=>
          string(7) "Celsius"
        }
        [1]=>
        array(3) {
          ["value_raw"]=>
          int(-32768)
          ["value_localized"]=>
          NULL
          ["unit"]=>
          string(7) "Celsius"
        }
        [2]=>
        array(3) {
          ["value_raw"]=>
          int(-32768)
          ["value_localized"]=>
          NULL
          ["unit"]=>
          string(7) "Celsius"
        }
      }
      ["signalInfo"]=>
      bool(false)
      ["signalFailure"]=>
      bool(false)
      ["signalDoor"]=>
      bool(false)
      ["remoteEnable"]=>
      array(2) {
        ["fullRemoteControl"]=>
        bool(true)
        ["smartGrid"]=>
        bool(false)
      }
      ["light"]=>
      int(0)
      ["elapsedTime"]=>
      array(2) {
        [0]=>
        int(0)
        [1]=>
        int(0)
      }
      ["spinningSpeed"]=>
      int(1200)
      ["dryingStep"]=>
      array(3) {
        ["value_raw"]=>
        NULL
        ["value_localized"]=>
        string(0) ""
        ["key_localized"]=>
        string(12) "Drying level"
      }
      ["ventilationStep"]=>
      array(3) {
        ["value_raw"]=>
        NULL
        ["value_localized"]=>
        string(0) ""
        ["key_localized"]=>
        string(11) "Power Level"
      }
    }
  }
}

Hi! Glad you liked it! I really thought I had added MQTT username/password, but maybe I forgot. It seems like the power level is unavailable. -But I will add the data to the script in the next few days!

Regards,

Ole

Hello again.
I was working on the script today to add the washing machine, and noticed that I already did have support for washing machines (thanks to someone who calls himself Stoffi).

If there is any value among what you see in your JSON that you would like me to add to the washing machine template, please let me know :slight_smile:

Hello!

Sorry, I only received this through mail, and my Openhab account is linked to GMail, which I actually don’t use…

There was some problem with the authorization on Miele’s side of things, so even when you were authenticated correctly, the API would just give you a 404 - Access Denied when querying for devices. Miele has now launched version 1.0 (non-beta), and it seems this part is working again. I did run my dishwasher yesterday without getting any information from Miele, so I will revisit, and make sure everything works now.

Regards,

Ole

Currently all I get is a configuration error asking whether I have provided the correct credentials.
This is with the same configuration which was working in the past, as well as when I try to do it from scratch.

I got it working in the past by redoing the configuration (maybe got an updated token in the process) but this time it did not work.

Is there any debug I can enable in order to get an actual output of the step where the script fails for me?

For me, it started working again a couple of weeks ago, as Miele launched the “final” 1.0 version of the API. -But if you get a question about “correct credentials”, this means the system was unable to create your config. When you have run it, do you have write access to where the config file is stored?

Could you delete your current config file (or rename it in case you need to get your client ID and client key from the old config), make sure you are able to write to the config file, and post all the output if it doesn’t work? If you still have problems, I might have to put some more debugging code in there.

Thanks for still working with me. Seems I am the only one with regular issues.
Currently running the script as root. Root can also manipulate the files without problem at the location they are saved.
Still get this:

PHP Notice:  Undefined offset: 1 in /storage/docker/openhab/userdata/miele-MQTT.php on line 140
PHP Notice:  Undefined variable: code in /storage/docker/openhab/userdata/miele-MQTT.php on line 170
Failed to create config! Did you type the correct credentials?

Meanwhile resetted my password, but no change.

Unfortunately I do not have a previously working config available.
Is there a way to create it without the script? If i recall correct, password is being scrambled when the config is set up.

Ok, there is definitely an authentication error going on. The flow of Oauth2, which is the authentication protocol that Miele use, is to use your Client ID and Secret, combined with your Miele username and password to generate an Oauth token. So, the “scrambled password” is not a password, it is an authentication token (think of it as a ticket into the system), and can only be generated by combining these properties.

So, unfortunately, one of the four, Client ID, Client Secret, username, or password that you use is invalid. (Actually, it seems the secret is not used until the next step, so I would believe it is your username and password. You can test the authentication flow here: https://www.miele.com/developer/swagger-ui/index.html At the right side, a little below the middle of the page, you will see an “Authorize” box you can use to Authorize, and as such, test your credentials.

Alright. So i tried it through the website (thanks for pointing it out) and it worked.
I then immediately tried to run the script and it worked as well and created a new config and gave my device status through MQTT.

So as I had to click “allow device (or similar)” on the website, it seemed as if I had to login once to obtain permissions with my client ID.

Oh, cool! They probably made a change then, that I didn’t know about. I will add that to the description! Thanks!