Midea Aircon control via NPM (non-Node-Red) package

Good Day!

I have a few Midea Aircons that I wish to control... There is an NPM package that has been compiled here: https://github.com/reneklootwijk/node-mideahvac

I have run the following discovery routine successfully:

# node_modules/.bin/midea-discover [--user=<MSmartHome user>, --password=<MSmartHome password>]

and the little pi can see my aircons and return the data from the discovery routine...

Now... The BIG question: Not being familiar with this type of enviro (read that as trying to get info into node red), is it possible to use maybe an exec node perhaps to send/retrieve the info to/from the npm package that I installed (npm install node-mideahvac) ?

There is reference to "creating an appliance" :

const appliances = require('node-mideahvac')

var options = {
    communicationMethod: 'sk103',
    id: <the id of the device to control>,
    key: <the key for the device to control>,
    token: <the token for the device to control>
}

var ac = appliances.createAppliance(options)

and then an example is given to "set the appliance":

ac.setStatus({ powerOn: true, setpoint: 24 }, 3)
.catch(error => {
    console.log(error.message)
})

but, unfortunately, my knowledge has definite bounds in this area (also unfortunately, my stupidity is limitless in this same area)....

Any assistance would be appreciated immensely!!

TIA
Ed

Yes. But, since you are already implementing a low-code platform built on node.js, you might find one or two easier ways :wink:

So recent versions of Node-RED allow you to attach a node.js module such as node-mideahvac to a function node. Have a look at the setup tab. Once you've done that, you can use that exact code in the function - except that you don't need the require statement since setup does that for you.

In addition, you will want to change the console.log statement to a node.warn.


Once you've tried some basics. You will probably want to pass the ac variable to a node-red global or flow variable with something like flow.set('ac1', ac). That will let you retrieve it in other function nodes with const ac = flow.get('ac1', ac) and then you can use it like the other examples for that package.

Hi Julian,

Thanks ever so much!!

I will finish dealing with the office chores and give it a go!!

Regds

Ed

@TotallyInformation

HeyHey!!

A little bit of progress.... Could you tell me if my "syntax" is correct?

The setup for the function node (node-mideahvac is a subdirectory of: /home/pi/.node-red/node_modules)

The dreaded code:

var options = {
    communicationMethod: 'sk103',
    host: '192.168.0.102',
    id: 'mynumbers',
    key: 'moreofmynumbers',
    token: 'stillmoreofmynumbers'
}
var Study = mideahvac.createAppliance(options);
node.warn(Study.getStatus(3))
msg.payload = Study.setStatus({ powerOn: true, setpoint: 24 }, 3)
return msg

And the responses I get from it:

screenshot-192.168.0.118_1880-2022.05.12-11_27_31

As to what a "Promise" is.... Well.... all I know is that most of them are broken!!

Thanks Stax for the help!!!!

Regds
Ed

OK, you are making progress.

A Promise is a way of handling asynchronous requests that is common for JavaScript and node.js.

You need to add a bit more code to realise the promise. Something like:

var options = {
    communicationMethod: 'sk103',
    host: '192.168.0.102',
    id: 'mynumbers',
    key: 'moreofmynumbers',
    token: 'stillmoreofmynumbers'
}
var Study = mideahvac.createAppliance(options);
Study.getStatus(3)
    .then( (x) => {
        node.warn(x)
        msg.payload = Study.setStatus({ powerOn: true, setpoint: 24 }, 3)
        return msg
    })
    .catch( (err) => {
        node.error(err.msg)
    })

BTW, that's a guess about how the promise needs handling and what data might be passed to the then function.

1 Like

Hi @TotallyInformation !!

I gave it a good go... (6hrs of try this try that.....)

All I managed to do was get the pi to crash and reboot intermittently...

Even went so far as to slap an ESP together with a level shifter ... Ran it on ESP-Link ... That allowed for the "non - cloud" comms to be used instead on the midea node....

At least with the ESP linked up, I got a few responses from the aircon, albeit with a message "CRC Error" which was visible from the ESP-Link debug screen...

I think that I might have to call it on this one until I can find some info on the communications protocols that are used...

And probably just wait until an "official" node is available on the palette..

Regds (And thanks heaps for your time and trouble!!)
Ed