Closed Wob76 closed 5 years ago
I think Node-Red to MQTT might be good. That's what I'm thinking of. I haven't made a UI for myself yet, just Alexa.
Added your additional information to the read-me, so thanks for that
Most of the open automation systems will talk to either nodered via MQTT, so that will prob be the route I go down.
Have you done any working decoding the responses from melview? I noticed it sends a message with no command quite frequently to get a status response, some of them are obvious, power, temp etc, It would be nice to decode the status of the unit so that could be used in the automation system.
I'll keep posting information as I decode it, Off on a weeks holiday so won't get to play for awhile.
Regarding my blocking by melview, just a not to be careful when testing, I am thinking I triggered it while playing with storing the cookies in nodered.
The reply I got was;
The IP was blocked by the inbuilt safety protocols. We were getting odd access errors from your IP address, so a block was temporarily put in place. It may have been some problem your internet at the time. It’s been resolved now, our apologies for any inconvenience.
I do a GET command every 5 minutes. I store the cookie and request a new one every month.
I don't worry about decoding HTTPS. I get all the info I need from the commands I mentioned
Thought you might be interested I have decoded the non-https messages and it looks like it is possible to send instantaneous messages what that also means it is it possible to bypass Melview all together.
Melview sends a XML command in its response which is then passed to the local unit to process immediately.
The key is to have the command "lc":1 in your unitcommand request.
That's very interesting, I did notice in the website traffic it call a gif image from the wifi unit, that did get me thinking about talking direct to the unit. It would avoid the delays going to/from the melview servers.
Are you able to post a little more detail of you testing.
Thanks, Wob
I updated the read me. Look into that.
I am not going to do direct commands its too much work with little gain. Feel free to decode the XML yourself and work it out. If you do it locally you get no status.
I have made a UI for it. Not functional yet.
Hi there - and thanks for sharing your work!
I am trying to figure how to make some use of it, but with little success; I wrote this bit of code and when I run it I can apparently connect, but that's it:
`var MMcontrol = require('mmcontrol');
var controller = new MMcontrol({ 'username': 'xxx@yy.org', 'password': 'yyyy' });
controller.connect(true, function (err) { if (err) { console.log("couldn't connect: " + err); } else { console.log("connection established"); }});
controller.connect(true, function(map){ console.log(map) });
controller.getCurrentState(0, function (err, state) { if (err) { console.log("couldn't get the current state: " + err); } console.log(JSON.stringify(state, null, 1)); }); ` Output is: /home/nodereduser/.node-red/node_modules/mmcontrol/libs/index.js:998 for (i in self._capabilities[unitid].modelData) { ^
TypeError: Cannot read property 'modelData' of undefined
at MMcontrol.getCapabilities (/home/nodereduser/.node-red/node_modules/mmcontrol/libs/index.js:998:41)
at Object.
What am I doing wrong?
Could you please help me write a simple node code example that logs in, and reads the current state (controller.getCapabilities) then maybe sends one command (on/off)?
If I can run this from command line with node, then I think I will be able to do the rest myself...
Much appreciated!
BTW; ideally, I would make a Node.red flow using these commands... if anyone has flow example - no matter how simple... :)
Where did I say this uses mmcontrol?
Please follow the read me. Its only http commands. Please try again with pure http commands and please post your own issue and don't hijack this one.
Here is the flow as requested. Change username and password in inject node
[{"id":"a21dd252.9b89d8","type":"inject","z":"461380e6.25dc1","name":"Get Cookie","topic":"","payload":"{\"user\":\"test.com\",\"pass\":\"superpassword\",\"appversion\":\"3.0.539\"}","payloadType":"json","repeat":"","crontab":"","once":false,"x":108.76666259765625,"y":70.01666259765625,"wires":[["6c8c7f8.b3fa9"]]},{"id":"1d94b22c.4fbd9e","type":"http request","z":"461380e6.25dc1","name":"Login.aspx","method":"POST","ret":"obj","url":"https://api.melview.net/api/login.aspx","tls":"","x":448,"y":70,"wires":[["a5920f6a.fd49d8"]]},{"id":"a5920f6a.fd49d8","type":"function","z":"461380e6.25dc1","name":"Store Cookie","func":"var aircon_cookie;\n\naircon_cookie = msg.headers[\"set-cookie\"][0];\nglobal.set(\"aircon_cookie\",aircon_cookie);\n\nreturn msg;","outputs":1,"noerr":0,"x":637,"y":70,"wires":[[]]},{"id":"6c8c7f8.b3fa9","type":"change","z":"461380e6.25dc1","name":"Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"User-Agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":276.5,"y":70,"wires":[["1d94b22c.4fbd9e"]]}]
Hi,
Back from holiday and having another look at this... Thanks for the flow post, that has helped me get started.
I am very new to this, I do plenty of scripting, but programming not so much.
I ran a function on the aircon_cookie, to split it up and just pull out the "auth" part, for my return cookie, this is working, and I have set up a couple of test flows to turn the unit on\off and the same with the zones. So far working in its basic form.
A should be able to have a single flow and just build the command sent from the inputs, but need to work up to that.
I received my Xiaomi Gateway and Temp Sensors, I have 5 throughout the house, I have them set up in both Domoticz and Home Assistant.io, Both seems seem good, I am liking Domoticz for its temp graphing, but need to explore both a little more, just need to look into MQTT for both and how to feed that into nodered.
Am i understanding the local command correctly, do you need to prob melview of a new LC Key each time? Or is that key valid for a period of time? Does the unit respond to commands or can you locally query it's state?
Thanks, Wob
@NovaGL I have made progress, still fairly new to nodered, my flow is bigger than ben hur, but it is working, I have incorporated some error checking, and I am ensuring temps limited to the min\max temps.
I have it talking via MQTT to Domoticz and data is flowing in both directions. Pretty happy with the result, but tweaking it each day.
MQTT seems very "chatty" or at least Domoticz is, it will repeat back changes after it processes my updates from melview, it limit my web chatter I am storing the states of devices when melview responds (either to a update request once every 5 min, or when a command is issued) If the outgoing command matches the existing state it is not sent to melview. This seems to work well.
I am not quite sure how to handle cookie expiration, if I set a inject node to 730 hours (a month) then my nodered hangs, my error handling will flush and re get all variables from melview (cookies, unitid, and unit capabilities) if it receives anything other than an "ok" in the payload.error, so this should happen when the cookie expires. I am storing the expires date in the format "Tue, 07-Nov-2017 01:26:27 GMT", but couldn't work out an easy way to compare that with the current date. Any advice?
I can see why you where reluctant to post flows. It's not exactly portable, needs a fair bit of matching up to the AC unit and domoticz "devices". I've tried to keep most things in variables, but if you have more than 1 unit or more than 4 zones it will need modification. I am sure if you had access to the underlying library of commands, or even more test units you could have much of it built from the responses from melview. It is a shame they are building a closed system.
Strange that your MQTT is "chatty" it should only update every 5 minutes when you update via MelView or issue a command yourself.
Why does your Node-Red hang? Something weird there. I just set mine to be once a month. Another alternative is to inject everyday and only pass through when date matches cookie date. To compare dates get a plugin that uses moment to convert dates.
All my variables are dynamic. So I don't need to duplicate anything. You just loop through room names, save each in its own variable.
If interested here is my flow. Save repeated actions in subflows.
It isn't my flow that is chatty, it is the automation system "Domoticz", it assumes ownership of devices in it, so even though I am inputting a change via MQTT it feels the need to republish those changes back to MQTT, that said it does include more data.
I'll investigate more on the dates, my inject node didn't have months, highest value is hours, and it just didn't seem to like big values, I am running it inside a docker, not sure if that is an issue? I am fairly confident my error checking process will work if the cookie expires anyway, but as it last 3 months it will be awhile before I can test the theory.
My flow is doing translation on the json between melview and domoticz, I need to tell it the "ID" of the "virtual" switches I created in domoticz as well as the switch states on my "selector" switches for fan speed and modes, I did have these defined in the fuctions, but pulled them out to variables so I could just change them in 1 place.
I could simplify my flow dramatically by using functions a little more, but I tired to use default (switch and change) nodes where I could, it also helped my learn\visualise. I have some subflows for global variable and error checking processes, but anything working on my flow context couldn't go into a subflow unless I inserted those variables into the payload as the subflow doesn't have access to the parent context.
I would like to get a look at your full flow, if only to learn a little from it, not necessarily use it.
Your flow is more complex than mine as mine only deals with Alexa and I haven't put error handling in like you have.
To stop it being chatty, I allow commands to be send via HTTP POST also I can poll using HTTP GET if MQTT is not available.
Next thing you should try is JSONata it's really quite amazing and very useful in the change node.
I do, "at specific time" for the inject node and have it doing it once a week.
If you want me to look into your flow feel free to post it but it might be hard for me to work out since I don't use Domoticz
Noticed something very interesting.
My units are showing COMM error, but if I include the command lc:1 the commands go through successfully.
It complains that there is a communication error but on the Air con panel it does switch on and off as instructed.
I also got this working with Google Home using IFTTT to pass the command
Thanks for the offer of checking my flows, I have a few tweaks I want to do yet.
It works great for the most part, and it has enabled me to get the level or automation I was hoping for, but I still see room for improvement.
My flow could prob do with some optimising, but really the resource requirement and pretty low anyway.
More hoping to make something that could be used by others, but I think without melview opening up, or having a heap of units it would just be too easily broken.
My unit reports
I would be VERY interested in your Google Home\IFTTT flows, considering getting myself a home, having it talk to the AC would prob get me over the line :)
Mine doesn't break, just the cookie that might cause an issue. But if Melview API keeps changing there is potential for breaks.
In terms of Alexa vs Google Home for this purpose I believe Alexa is the stronger of the two.
It was really easy with this setup to get Alexa to talk to it. You can even ask her the current temperature in the room.
With Google Home I could only send commands couldn't request status. It's really easy. Just have a service that allows HTTP POST to Node-Red and then the rest is the same.
Here is an example of how it would work using Harmony as the example. https://github.com/NovaGL/diy-ifttt-harmony
Thanks for the info, I had a bit more of a look and both automation apps I am looking at (Domoticz) and Home Assistant, have some level of Alexa and Google Home support. So might tackle it from them, would make it more functional.
Alexa seems like it is much more capable with them than Google Home, but I am still leaning towards Google Home as I have a big foot in the google pond so to speak.
I've been doing some tweaking to my initial design and thought you might be interested. To prevent loosing the cookie I save it on MQTT on launch. On load that MQTT topic is pushed into the get rooms section so it gets the current room data.
An inject node runs every 5 minutes, before progressing it checks the cookie expiry date against the system data, If the cookie date is greater than the system date it proceeds if not it requests a new cookie.
Retaining the cookie data means I don't need to request it as often and MQTT always has the latest value, so there is no worry of Node-Red loading and then causing an issue as no cookie is present.
Have you done any further work on this. I've also integrated Homekit into mine Eg your Google Home integration?
Interesting, when you say you save it to MQTT, are you pushing that MQTT to something else or storing it with your MQTT broker?
My system has been fairly robust, I am using MQTT to talk to Domoticz (My home automation system), I store most of my system variables in nodered variables. I don't actually do any date checking of my cookie (probably should revisit that), but I do a error check after each command, if it gets an sort of error it will flush all my variable and reinitialise, grabbing cookie, unit id and all the other system data. Seems to keep the cookie fresh enough.
I have 2 "streams?" in my flow, 1 probs melview and pushes data via MQTT to Domoticz, the other receives MQTT from Domoticz and actions melview if required, using payload.lc to issue the local unit a command. So the first will update Domoticz if I happen to use the in house panel, or the mitsubishi app (this runs every 5 mins), the second flow allows me to control the system from Domoticz, I also trigger stream 1 if stream 2 actions the local system, to ensure everything stays upto date.
I was having some timing issues, If I happened to action stream 2 while stream 1 was working, etc, I put in some rate limits and delays, but still saw some odd behaviour, I have since started using the timestamp in the header response from melview and the last update time of the switches in domoticz, if the time of domoticz is newer then it pauses stream 1 and loop back to run it again.
I also store all melview states in variables, to reduce my chatter to melview, if I request it change to a state it is already in, it will be dropped. Seems to behave fairly well, and no bans from melview.
I have my Google Home working with Domoticz now, so I control the AC via that.
So the way mine works is like this
aircon/{room}/{action}
So I store the cookie in Aircon/Cookie which is published every time the cookie changes. That way if there is an outage the cookie info is retained.
I do all commands via MQTT. So it would be
aircon/bedroom/status
Which contains the status of the device, this topic gets updated every 5 minutes, if an action is performed the topic gets updated.
To peform an action you publish to aircon/bedroom/set
eg {"power":0 }
would turn off the power. {'mode':8}
would change mode to auto.
Or {'tempchange:22}
would change the temperature.
I still use global variables but am not reliant on them, using MQTT means any platform can easily update the state.
Makes sense, I built my flow to suit domoticz MQTT, so JSON data and MQTT topic is a little different. I also had to live with the Selector values it has, so I am storing values in variables to translate.
For example Domoticz has a "Mode" switch; Auto = 10 Heat = 20 Dry = 30 etc
Melview is 8, 1, 2 for the same value, so just need to translate between.
It should be simple enough to update if I migrate to another automation system, and I have been testing a number of them, but domoticz is still my top choice for a few reasons.
I stumbled across this after searching for info on the Mitsubishi wifi controller app's change history on Google Play. Mentioned external app support via a URL scheme. I've emailed Mitsubishi to see if I can get any more info on the API or interface spec. I have a single split system with the wifi controller and am also using Domoticz. I noticed a little while ago one of the app version showed both the internal split system thermostat temperature and also the temperature outside in the condenser. Would be interesting if this was available still. I've found the internal temperature control to be pretty far off given the thermostat is in the spit system itself when compared to my Xiaomi temperature sensors. I'll try and get it working with node red as it can compliment my Broadlink blackbean IR senders that I've currently got set up in Domoticz.
Mine doesn't do that so can't be of help. It only shows room temp and set temp. I recommend using MQTT to store information so it can be used on any platform
Just received the URL scheme from Mitsubishi and realised you already had it. Unfortunately didn't even work for me and was less useful than I thought it would be. Can't be used in any way to trigger from a Raspberry Pi I presume? It does seem like a safer and more straightforward way of doing things.
That API is only for use on device where the Mitsubishi App is installed, eg Android or iOS. It is not a standalone API.
Hi,
Thanks heaps for the information thus far.
I have a ducted system, model name is PEA-RP140GAA. I have 4 Zones, but the unit is capable of up to 8.
I have just started out by using the developer mode in chrome to watch the commands sent when setting functions via the melview web app, so far this is a list of my commands. Most match up with yours, I just have a few extra due to the zones.
Power and Set Temp commands are identical to your settings.
Fan Speed also matches with yours, but I only have 3 settings (Low, High and Auto) they are; Low - FS2 High - FS5 Auto - FS0
I have 5 Modes as follows MD1 - Heat MD2 - Dry MD3 - Cool MD7 - Fan MD8 - Auto
Zones can be turned on\off independently They are formatted as Z[0-8][0-1] Digit 1 is the Zone Digit 2 is the on off flag So Z10 (Zone 1 Off) Z11 (Zone 1 On) Z20 (Zone 2 Off) Z21 (Zone 2 On) etc
I still need to work out nodered as I am very new to it, cooking handling etc.
My goal is to have some temp sensors in each Zone (I have ordered a xiaomi gateway and sensors) and have them turn the zone on\off if a Max\Min temperature is reached, this is primarily a fail safe as we have had the kids rooms over heat\cool compared to the main zone, we do have the AC people coming to tweak, but I would look a automated fail safe as at the moment we just use baby monitors to monitor the room temp.
The xiaomi system is compatible with the open source home automation systems (OpenHAB, Domoticz and maybe Home-Assistant.io) so I can either link to one of those via nodered and MQTT or I may revisit Domoticz and its plugin system, someone has written one for MelCloud, the European equivalent of melview, so with this data I may be able to update it to work with MelView.
Thanks for your help, I'll keep tinkering away and let you know my results.