Author Topic: Tempurpedic Wifi Frame  (Read 685 times)

Offline tcarlig

  • Sr. Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Tempurpedic Wifi Frame
« on: March 01, 2018, 02:20:07 pm »
I just purchased a king size Tempurpedic mattress with the movable base and Massage built in. It has Wifi capability and can be set to a static IP address which I have done. I am able to use the app they have provided from the Play Store and iTunes store but would like to integrate this into Vera. I found on the web someone has done research on this where I know the Hex codes and port, etc. Here I just don't know how to execute this thru the Vera... Once I can execute I'm really just trying to create a scene to lay it flat at a certain time and possible have it work with the Amazon Echo thru the Vera.

Any help would be appreciated,
Thanks!
TC

Offline jswim788

  • Hero Member
  • *****
  • Posts: 735
  • Karma: +49/-2
Re: Tempurpedic Wifi Frame
« Reply #1 on: March 01, 2018, 02:39:46 pm »
@akbooer gave an example of sending UDP in Lua code which you can see here: http://forum.micasaverde.com/index.php/topic,35374.msg261138.html#msg261138

You could add that Lua code to a scene and change the IP and port and command to match what the person researched.

I highly recommend that you install AltUI to get the Lua test code window for debugging this even if you use it for nothing else.  You'll probably need a few iterations to get the Lua code to do what you want and it is much easier to use AltUI's test code window than what is provided in the standard UI.

Good luck!

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1173
  • Karma: +23/-13
Re: Tempurpedic Wifi Frame
« Reply #2 on: March 01, 2018, 03:12:22 pm »
I highly recommend that you install AltUI to get the Lua test code window for debugging this even if you use it for nothing else.  You'll probably need a few iterations to get the Lua code to do what you want and it is much easier to use AltUI's test code window than what is provided in the standard UI.

Not disagreeing - but since this is standard LUA, if it were me I would instead build and test in Lua for Windows.  Can have your laptop with you on the bed, and execute the commands via SciTE development environment.  Once you get what you want, copy into Vera...
Long Live UI5!  (OK finally made the switch to UI7 in January 2018, and am pretty happy....)

Offline tcarlig

  • Sr. Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Re: Tempurpedic Wifi Frame
« Reply #3 on: March 02, 2018, 03:02:09 pm »
Thanks guys for the Info. I'm really a newbie for development So for the example in the link you shared... In red below is what need to be changed?

Not sure what the Socket is... is this the Hex code?

local ip, port = "127.0.0.1", 2003       -- change these to what IP and PORT you need
local message = "whatever message you like"
local socket = require "socket"
sock, msg = socket.udp()
if sock then
  sock:setpeername(ip, port) end         -- connect to destination
  sock:send(message)
  sock: close()
end

I assume for my situation:

local ip, port = "20.1.0.32", 50007                        -- change these to what IP and PORT you need
local message = "Testing-Testing-Testing"
local socket = require "3305320A945C0400CC"      -- To lay it flat
sock, msg = socket.udp()
if sock then
  sock:setpeername(20.1.0.32, 50007) end            -- connect to destination
  sock:send(message)
  sock: close()
end

Also can this be tested under "Test Luup code (Lua)" within the Vera
I looked at Lua for windows but couldn't figure out how to install and run it... :)

I'm just looking for simple plug in and execute if possible? All I know is my ip address, port and the Hex codes figured out from the website above..

Thanks again for your help.
TC

Offline jswim788

  • Hero Member
  • *****
  • Posts: 735
  • Karma: +49/-2
Re: Tempurpedic Wifi Frame
« Reply #4 on: March 02, 2018, 08:03:48 pm »
Can it be tested with the built in test area?  Sure, but it is painful to use.  You'll definitely want to be looking at the log file.  I suggest another try at getting Lua running on either a Windows or a Linux box to test this if possible.  As to the code, perhaps something like this.  The message is the hex code.  Your IP address looks a bit odd, but it is possible.  Usually you would have 192.168.1.xx or similar.  But maybe that's right for your network.

You can try this, but it's going to be really hard to help you debug remotely.  It would be best to have a packet sniffer as the researcher had to see what it is doing.

Code: [Select]
local ip, port = "20.1.0.32", 50007                        -- change these to what IP and PORT you need
local message = 0x3305320A945C0400CC
local socket = require "socket"      -- To lay it flat
sock, msg = socket.udp()
if sock then
  sock:setpeername(ip, port)         -- connect to destination
  sock:send(message)
  sock: close()
end
« Last Edit: March 02, 2018, 08:13:51 pm by jswim788 »

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1173
  • Karma: +23/-13
Re: Tempurpedic Wifi Frame
« Reply #5 on: March 04, 2018, 01:47:33 pm »
I looked at Lua for windows but couldn't figure out how to install and run it... :)

Just one file to download.
Main page:  https://github.com/rjpcomputing/luaforwindows

Download page:
https://github.com/rjpcomputing/luaforwindows/releases
Long Live UI5!  (OK finally made the switch to UI7 in January 2018, and am pretty happy....)

Offline tcarlig

  • Sr. Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Re: Tempurpedic Wifi Frame
« Reply #6 on: March 05, 2018, 04:09:09 pm »
Thanks Guys! I was able to load Lua for Windows and tried loading in what you suggested and run it. This is what I received back... My IP scheme is a little different but it is correct. I am able to query the Adjustable frame by the web and port as the post suggested... Anything else you think I can try... Thanks again for your help! (attached)

TC

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1173
  • Karma: +23/-13
Re: Tempurpedic Wifi Frame
« Reply #7 on: March 05, 2018, 04:32:15 pm »
What did you get back?  Print it to the screen...  Here is an example of checking for errors in the send and receive.
My guess is you need quotes around the hex. 


Code: [Select]
local socket = require("socket")
host = "192.168.0.123"
c = assert(socket.connect(host, 4999))
c:settimeout(5)

local sres, serr = c:send(CommandtoSend)
print("Send:", sres, serr)
local data, rerr = c:receive(5)
print ("Receive:", data, rerr)

c:close()
« Last Edit: March 05, 2018, 04:34:42 pm by wilme2 »
Long Live UI5!  (OK finally made the switch to UI7 in January 2018, and am pretty happy....)

Offline jswim788

  • Hero Member
  • *****
  • Posts: 735
  • Karma: +49/-2
Re: Tempurpedic Wifi Frame
« Reply #8 on: March 05, 2018, 08:27:00 pm »
My guess is you need quotes around the hex. 

I was wondering about that too.  But based on @futzle's post (http://forum.micasaverde.com/index.php/topic,32046.msg233030.html#msg233030), I'm thinking that it needs to be something like this.  I have no way to test this, so can't tell if it is on the right track or not.

Code: [Select]
local hex = { -- 3305320A945C0400CC
  "33", "05", "32", "0A", "94", "5C", "04", "00", "CC"
}
local binary = "";
for i, v in ipairs(hex) do
  binary = binary .. string.char(tonumber(v, 16))
end
local ip, port = "20.1.0.32", 50007
local socket = require "socket"
sock, msg = socket.udp()
if sock then
  sock:setpeername(ip, port)         -- connect to destination
  sock:send(binary)
  sock:close()
end

Offline tcarlig

  • Sr. Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Re: Tempurpedic Wifi Frame
« Reply #9 on: March 10, 2018, 11:44:24 pm »
Sorry for the late response, been traveling. Awesome guys, the last one worked! now to create a scene and device to use it :-)  Thanks again for your help!

... Do either of you have any tips on creating a device from this code? Little stuck on this now. :-)

Thanks,
TC
« Last Edit: March 12, 2018, 12:05:16 am by tcarlig »

Offline tcarlig

  • Sr. Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Re: Tempurpedic Wifi Frame
« Reply #10 on: March 12, 2018, 11:40:49 pm »
Hey Guys anyone know how to make this script a device now?

Thanks,
TC

Offline jswim788

  • Hero Member
  • *****
  • Posts: 735
  • Karma: +49/-2
Re: Tempurpedic Wifi Frame
« Reply #11 on: March 13, 2018, 12:02:03 am »
Just curious - what are you expecting from a plugin device over what you have now?  It is possible to have a plugin that has actions that correspond to the mattress commands, but that wouldn't be anything more than what you have now with scripts.  It would give you something to see in the GUI, but unless you know the commands to query the mattress, it probably wouldn't be able to show the state of the mattress.  I guess it would consolidate the actions from a set of scenes to one device with multiple actions.  That might be a good reason.

Offline tcarlig

  • Sr. Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Re: Tempurpedic Wifi Frame
« Reply #12 on: March 13, 2018, 10:42:11 am »
Typically I sleep in position 2 at night, I would want to set a scene to make it go flat at 6:00 am. on weekdays, which will wake me up without an alarm going off. I noticed if I run the command when its already flat it does nothing, so no harm if it runs.

Another use for it being a device is I can integrate it with the Echo plugin for voice commands to set positions or massage modes.

I use a lot of other plugins as well with the Vera... Another example, My Elk plugin gets triggered by the basement door or window opening at night, set the bed to flat or turn to massage preset 2 in case I miss the chime the Elk is set to. Lots of possibilities.

And I Just like tinkering.  :-)

Thanks,
TC

Offline jswim788

  • Hero Member
  • *****
  • Posts: 735
  • Karma: +49/-2
Re: Tempurpedic Wifi Frame
« Reply #13 on: March 13, 2018, 04:51:17 pm »
You don't need a device to handle the schedule you mention, just put the Lua in the scene code.  You probably already knew that.  Scenes get triggered and can run the Lua as needed.

I'm not the best person to explain how to build a plugin, but my suggestion is to try to find a similar plugin and modify it for your needs.  One suggestion is the Virtual Switch plugin.  Your device doesn't appear to need any initialization; it's just a bunch actions.  Look at the I_VSwitch.xml file and the actions.  You'll need to modify them and add to them as needed.  You'll also need to update the other associated files in the plugin.  It's not trivial to do this as much is undocumented, but if you start with something working and make incremental changes it probably isn't too hard.  I don't think you'll need any device variables.

Offline tcarlig

  • Sr. Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Re: Tempurpedic Wifi Frame
« Reply #14 on: March 16, 2018, 09:29:48 am »
Of all the years I've been using the Vera through every model and software version they've had, I've never used that scripting in a scene. (Learn something new ever day)  Thanks again for your help! Now I can control the scene from the Authomation widgets on my Phone and my Echo!!! I'll tinker with your other suggestion as well, just need to find the time.  8)

Thanks again,
TC