Cloud-based Miele@home to MQTT

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!

Hi Ole,

as it seems that we are the only ones using this script :wink:
Do you have issues with the connection to the API from time to time? I just had to re-connect myself again to the API yesterday as the script kept failing during the past days.
That means going to the Miele API homepage again and re-linking my account via the “Authorize” Button.
Then I had to reconfigure the script, obviously because of the new token required.

Hi!
Yeah, seems like we are completely alone here :joy:

It has been working quite reliably for a long time now, but I have experienced losing connections and having to recreate the config. I have never had to go back to the API, though. If you remove the config-file, and re-run the script manually, you should be asked for API key and secret, username and password, and then the “authorize” process should be automatic.

I am thinking about writing a completely new script, since I have had requests for adding the possibility to trigger actions. -And currently, I don’t seem to be able to find a way to read MQTT commands asynchronously with PHP, and trigger actions.

You are not alone! :grinning:

I am watching the thread. At the moment I use the old way with a local gateway, but thinking about to change it in the future.

So, keep up the good work!

Bye
HFM

1 Like

Hi,

unfortunately this whole MQTT Broker/Client/mosquitto stuff makes me complete lost.

I installed the mosquitto “thing” via openhabian on the same RPi.
I set up PHP, and your script is working. At least it gives an output.

I installed via paperui the mqtt binding.
I set up a mqttBroker. At least it shows “online”. But I have no clue what is meant at this stage with the channel (?). Only selectable Channel Type: “Publish trigger”…no clue.
I tried to setup a generic mqtt-thing, but this shows allways OFFline…no clue what to enter where.

I tried everything via PaperUI, but I am really lost…no idea how to get any output from the washing machine into openhab here.

Any help, what to setup and where would be highly appreciated.

Thanks in advance

Stefan

Ok, looks like if the main problem is the use of OH 2.4 together with mqtt. You have to restart OH :frowning:
Anyway, it looks like it works for me now as well :slight_smile:

Thanks!

Best regards
Stefan

Hello! Sorry I didn’t check the forum until now. Glad to hear you got it sorted! Sounds like your MQTT configuration was not completely set up, as the concepts are a bit different with the MQTT 2.x addon as compared to the previous 1.x binding.

Hello,
I have never used PHP before. Is it possible to create a short installation guide for opnenhab?
How must PHP be configured? I installed PHP via sudo apt-get install php5-cgi php5, but now I get an error in line 140 :
PHP Parse error: syntax error, unexpected ‘[’ in miele-MQTT.php on line 140

MQTT is no problem.
Thanks to you

Hello, Thomas!

Hmm… That sounds strange. PHP 5 is quite old, though, and I haven’t tested using that. I am currently using PHP version 7.x. Which Linux-distro and version are you on?

I use Docker for running Openhab these days, and install php and mosquitto into my container by installing the following packages: php-cli php-common php-curl php-json php-readline mosquitto-clients

Regards,

Ole

Hi Ole and Others!

Maybe I can also help to develop this Miele binding for Miele@home wifi products. I requested and received within a few minutes the Miele API client credentials :slight_smile:

I have php knowledge and am familiar with swagger-like services. I own the Miele DGM6800 and the WMV963. So we can add those to our collection :hugs:

Regards,
Rolf