SDNick484 / rectec_status

Scripts to talk to RecTec pellet smokers with WiFi controllers
Apache License 2.0
29 stars 4 forks source link

Support for Hassio & Home Assistant #3

Open chansearrington opened 4 years ago

chansearrington commented 4 years ago

Hey there,

I'm another RecTec lover (Bull) and really excited to come across this and wondering if you're interested in making this work for Home Assistant.

There are a few people over in the community that are looking for this.

I think it could help you achieve:

chansearrington commented 4 years ago

@SDNick484 Got the stuff extracted from the rectec app easy enough.

but I'm getting an Error

Error while setting up localtuya platform for switch 10:02:55 PM – Switch (ERROR)

Log Details (ERROR) Logger: homeassistant.components.switch Source: custom_components/localtuya/switch.py:46 Integration: Switch (documentation, issues) First occurred: 10:02:55 PM (1 occurrences) Last logged: 10:02:55 PM

Error while setting up localtuya platform for switch Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT) File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for return fut.result() File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/localtuya/switch.py", line 46, in setup_platform import pytuya ModuleNotFoundError: No module named 'pytuya'

SDNick484 commented 4 years ago

Looks like we need to change the line "import pytuya" to "from . import pytuya"

chansearrington commented 4 years ago

@SDNick484 Ok, looks like it's setup but has a connection error?

Logger: homeassistant.components.switch Source: custom_components/localtuya/switch.py:99 Integration: Switch (documentation, issues) First occurred: 8:43:47 AM (1 occurrences) Last logged: 8:43:47 AM

Error while setting up localtuya platform for switch Traceback (most recent call last): File "/config/custom_components/localtuya/switch.py", line 95, in get_status status = self._device.status() File "/config/custom_components/localtuya/pytuya/init.py", line 259, in status data = self._send_receive(payload) File "/config/custom_components/localtuya/pytuya/init__.py", line 171, in _send_receive data = s.recv(1024) ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT) File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for return fut.result() File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/localtuya/switch.py", line 76, in setup_platform config.get(CONF_ID) File "/config/custom_components/localtuya/switch.py", line 129, in init self._status = self._device.status() File "/config/custom_components/localtuya/switch.py", line 113, in status self._cached_status = self.get_status() File "/config/custom_components/localtuya/switch.py", line 99, in get_status raise ConnectionError("Failed to update status.") ConnectionError: Failed to update status.

chansearrington commented 4 years ago

@SDNick484 I'm not sure if this is the cause of the second error, but I'm currently using the "Packages" concept and Secrets.

So I have CONFIG > packages > rectec.yaml

###################################
# RecTec RT-700 Bull Package
###################################

###################################
# Climate
###################################

###################################
# Sensors
###################################

sensor:
 - platform: template
   sensors:
     rectec_target:
       value_template: >-
         {{ states.switch.rectec.attributes.target }}
       unit_of_measurement: 'F' 
     rectec_current:
       value_template: >-     
         {{ states.switch.rectec.attributes.current }}
       unit_of_measurement: 'F'      
     rectec_probea:
       value_template: >-
         {{ states.switch.rectec.attributes.probea }}
       unit_of_measurement: 'F'
     rectec_probeb:
       value_template: >-
         {{ states.switch.rectec.attributes.probeb }}
       unit_of_measurement: 'F'

###################################
# switch
###################################

switch:
  - platform: localtuya
    host: !secret rectec_host
    local_key: !secret rectec_local_key
    device_id: !secret rectec_device_id
    name: smoker

And then CONFIG > secrects.yaml

#RecTec
rectec_host: 192.168.1.223
rectec_local_key: 2a3c1a64ff1fca1g
rectec_device_id: 07200374b4e62d1b20dg
chansearrington commented 4 years ago

@SDNick484 in case it helps, here's my gw_storage.xml contents

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <string name="gw_groupaz154241g45746505CfIZJ7327d83ec3011f6c88581b6bb72d09bf7d">[]</string>
    <string name="gw_dev">[{&quot;ability&quot;:0,&quot;bv&quot;:&quot;5.24&quot;,&quot;devices&quot;:[{&quot;ability&quot;:0,&quot;appRnVersion&quot;:&quot;1.0&quot;,&quot;attribute&quot;:4,&quot;devId&quot;:&quot;07200374b4e62d1b20df&quot;,&quot;displayDps&quot;:&quot;[]&quot;,&quot;displayMsgs&quot;:&quot;{}&quot;,&quot;dps&quot;:{&quot;1&quot;:false,&quot;102&quot;:230,&quot;103&quot;:0,&quot;104&quot;:65,&quot;105&quot;:183,&quot;106&quot;:0,&quot;107&quot;:0,&quot;108&quot;:false,&quot;109&quot;:false,&quot;110&quot;:false,&quot;111&quot;:false,&quot;112&quot;:0,&quot;113&quot;:0},&quot;faultDps&quot;:[],&quot;i18nTime&quot;:1585277377201,&quot;icon&quot;:&quot;smart/product_icon/kx.png&quot;,&quot;iconUrl&quot;:&quot;https://images.tuyaus.com/smart/product_icon/kx.png&quot;,&quot;isOnline&quot;:true,&quot;name&quot;:&quot;Big Bear's Bull&quot;,&quot;panelConfig&quot;:{&quot;bic&quot;:[{&quot;code&quot;:&quot;timer&quot;,&quot;selected&quot;:false},{&quot;code&quot;:&quot;jump_url&quot;,&quot;selected&quot;:false}]},&quot;productId&quot;:&quot;1CwNbNLE8r70WR7t&quot;,&quot;quickOpDps&quot;:&quot;[]&quot;,&quot;rnFind&quot;:false,&quot;schema&quot;:&quot;[{\&quot;mode\&quot;:\&quot;rw\&quot;,\&quot;code\&quot;:\&quot;Power\&quot;,\&quot;name\&quot;:\&quot;电源开关\&quot;,\&quot;property\&quot;:{\&quot;type\&quot;:\&quot;bool\&quot;},\&quot;iconname\&quot;:\&quot;icon-dp_power\&quot;,\&quot;id\&quot;:1,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;rw\&quot;,\&quot;code\&quot;:\&quot;Set_temp\&quot;,\&quot;name\&quot;:\&quot;设定温度\&quot;,\&quot;property\&quot;:{\&quot;unit\&quot;:\&quot;\&quot;,\&quot;min\&quot;:0,\&quot;max\&quot;:65535,\&quot;scale\&quot;:0,\&quot;step\&quot;:5,\&quot;type\&quot;:\&quot;value\&quot;},\&quot;id\&quot;:102,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;ro\&quot;,\&quot;code\&quot;:\&quot;Actual_temp\&quot;,\&quot;name\&quot;:\&quot;实际温度\&quot;,\&quot;property\&quot;:{\&quot;unit\&quot;:\&quot;\&quot;,\&quot;min\&quot;:0,\&quot;max\&quot;:65535,\&quot;scale\&quot;:0,\&quot;step\&quot;:1,\&quot;type\&quot;:\&quot;value\&quot;},\&quot;id\&quot;:103,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;rw\&quot;,\&quot;code\&quot;:\&quot;Min_feedrate\&quot;,\&quot;name\&quot;:\&quot;最小下料量\&quot;,\&quot;property\&quot;:{\&quot;unit\&quot;:\&quot;\&quot;,\&quot;min\&quot;:0,\&quot;max\&quot;:255,\&quot;scale\&quot;:0,\&quot;step\&quot;:1,\&quot;type\&quot;:\&quot;value\&quot;},\&quot;id\&quot;:104,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;ro\&quot;,\&quot;code\&quot;:\&quot;Food_temp1\&quot;,\&quot;name\&quot;:\&quot;食物温度1\&quot;,\&quot;property\&quot;:{\&quot;unit\&quot;:\&quot;\&quot;,\&quot;min\&quot;:0,\&quot;max\&quot;:65535,\&quot;scale\&quot;:0,\&quot;step\&quot;:1,\&quot;type\&quot;:\&quot;value\&quot;},\&quot;id\&quot;:105,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;ro\&quot;,\&quot;code\&quot;:\&quot;Food_temp2\&quot;,\&quot;name\&quot;:\&quot;食物温度2\&quot;,\&quot;property\&quot;:{\&quot;unit\&quot;:\&quot;\&quot;,\&quot;min\&quot;:0,\&quot;max\&quot;:65535,\&quot;scale\&quot;:0,\&quot;step\&quot;:1,\&quot;type\&quot;:\&quot;value\&quot;},\&quot;id\&quot;:106,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;rw\&quot;,\&quot;code\&quot;:\&quot;Temp_adjust\&quot;,\&quot;name\&quot;:\&quot;温度校准\&quot;,\&quot;property\&quot;:{\&quot;unit\&quot;:\&quot;\&quot;,\&quot;min\&quot;:-128,\&quot;max\&quot;:127,\&quot;scale\&quot;:0,\&quot;step\&quot;:1,\&quot;type\&quot;:\&quot;value\&quot;},\&quot;id\&quot;:107,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;wr\&quot;,\&quot;code\&quot;:\&quot;Temp_unit\&quot;,\&quot;name\&quot;:\&quot;温度单位切换\&quot;,\&quot;property\&quot;:{\&quot;type\&quot;:\&quot;bool\&quot;},\&quot;id\&quot;:108,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;ro\&quot;,\&quot;code\&quot;:\&quot;ER1\&quot;,\&quot;name\&quot;:\&quot;ER1报警\&quot;,\&quot;property\&quot;:{\&quot;type\&quot;:\&quot;bool\&quot;},\&quot;id\&quot;:109,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;ro\&quot;,\&quot;code\&quot;:\&quot;ER2\&quot;,\&quot;name\&quot;:\&quot;ER2报警\&quot;,\&quot;property\&quot;:{\&quot;type\&quot;:\&quot;bool\&quot;},\&quot;id\&quot;:110,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;ro\&quot;,\&quot;code\&quot;:\&quot;ER3\&quot;,\&quot;name\&quot;:\&quot;ER3报警\&quot;,\&quot;property\&quot;:{\&quot;type\&quot;:\&quot;bool\&quot;},\&quot;id\&quot;:111,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;wr\&quot;,\&quot;code\&quot;:\&quot;Food_temp1_threshold\&quot;,\&quot;name\&quot;:\&quot;Probe A Threshold\&quot;,\&quot;property\&quot;:{\&quot;unit\&quot;:\&quot;\&quot;,\&quot;min\&quot;:0,\&quot;max\&quot;:65535,\&quot;scale\&quot;:0,\&quot;step\&quot;:1,\&quot;type\&quot;:\&quot;value\&quot;},\&quot;id\&quot;:112,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;},{\&quot;mode\&quot;:\&quot;wr\&quot;,\&quot;code\&quot;:\&quot;Food_temp2_threshold\&quot;,\&quot;name\&quot;:\&quot;Probe B Threshold\&quot;,\&quot;property\&quot;:{\&quot;unit\&quot;:\&quot;\&quot;,\&quot;min\&quot;:0,\&quot;max\&quot;:65535,\&quot;scale\&quot;:0,\&quot;step\&quot;:1,\&quot;type\&quot;:\&quot;value\&quot;},\&quot;id\&quot;:113,\&quot;type\&quot;:\&quot;obj\&quot;,\&quot;desc\&quot;:\&quot;\&quot;}]&quot;,&quot;schemaExt&quot;:&quot;[]&quot;,&quot;supportGroup&quot;:true,&quot;switchDp&quot;:0,&quot;ui&quot;:&quot;0000000167_&quot;,&quot;uiConfig&quot;:{},&quot;uiPhase&quot;:&quot;release&quot;,&quot;uiType&quot;:&quot;RN&quot;,&quot;verSw&quot;:&quot;1.0.0&quot;}],&quot;gwId&quot;:&quot;07200374b4e62d1b20df&quot;,&quot;gwType&quot;:&quot;s&quot;,&quot;icon&quot;:&quot;smart/product_icon/kx.png&quot;,&quot;iconUrl&quot;:&quot;https://images.tuyaus.com/smart/product_icon/kx.png&quot;,&quot;isActive&quot;:true,&quot;isOnline&quot;:true,&quot;isShare&quot;:false,&quot;lat&quot;:&quot;&quot;,&quot;localKey&quot;:&quot;2a3c1a64ff1fca1g&quot;,&quot;lon&quot;:&quot;&quot;,&quot;name&quot;:&quot;Big Bear's Bull&quot;,&quot;pv&quot;:&quot;2.1&quot;,&quot;runtimeEnv&quot;:&quot;prod&quot;,&quot;time&quot;:1586140387,&quot;updateCacheTime&quot;:1586140459924,&quot;uuid&quot;:&quot;07200374b4e62d1b20dg&quot;,&quot;verSw&quot;:&quot;2.2.3&quot;}]</string>
</map>
chansearrington commented 4 years ago

@SDNick484

Cleaned up version:

?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <string name="gw_groupaz154241g45746505CfIZJ7327d83ec3011f6c88581b6bb72d09bf7d">[]</string>
    <string name="gw_dev">
        [
            {
                ability:0
                bv:5.24,
                devices:
                [
                    {
                        ability:0,
                        appRnVersion:1.0,
                        attribute:4,
                        devId:07200374b4e62d1b20dg,
                        displayDps:[],
                        displayMsgs:{},
                        dps:{1:false,102:230,103:0,104:65,105:183,106:0,107:0,108:false,109:false,110:false,111:false,112:0,113:0},
                        faultDps:[],
                        i18nTime:1585277377201,
                        icon:smart/product_icon/kx.png,
                        iconUrl:https://images.tuyaus.com/smart/product_icon/kx.png,
                        isOnline:true,
                        name:Big Bear's Bull,
                        panelConfig:{bic:[{code:timer,selected:false},{code:jump_url,selected:false}]},
                        productId:1CwNbNLE8r70WR7t,
                        quickOpDps:[],
                        rnFind:false,
                        schema:
                            [
                                {
                                    mode:rw,
                                    code:Power,
                                    name:电源开关,
                                    property:{type:bool},
                                    iconname:icon-dp_power,
                                    id:1,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:rw,
                                    code:Set_temp,
                                    name:设定温度,
                                    property:{unit:,min:0,max:65535,scale:0,step:5,type:value},
                                    id:102,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:ro,
                                    code:Actual_temp,
                                    name:实际温度,
                                    property:{unit:,min:0,max:65535,scale:0,step:1,type:value},
                                    id:103,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:rw,
                                    code:Min_feedrate,
                                    name:最小下料量,
                                    property:{unit:,min:0,max:255,scale:0,step:1,type:value},
                                    id:104,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:ro,
                                    code:Food_temp1,
                                    name:食物温度1,
                                    property:{unit:,min:0,max:65535,scale:0,step:1,type:value},
                                    id:105,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:ro,
                                    code:Food_temp2,
                                    name:食物温度2,
                                    property:{unit:,min:0,max:65535,scale:0,step:1,type:value},
                                    id:106,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:rw,
                                    code:Temp_adjust,
                                    name:温度校准,
                                    property:{unit:,min:-128,max:127,scale:0,step:1,type:value},
                                    id:107,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:wr,
                                    code:Temp_unit,
                                    name:温度单位切换,
                                    property:{type:bool},
                                    id:108,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:ro,
                                    code:ER1,
                                    name:ER1报警,
                                    property:{type:bool},
                                    id:109,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:ro,
                                    code:ER2,
                                    name:ER2报警,
                                    property:{type:bool},
                                    id:110,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:ro,
                                    code:ER3,
                                    name:ER3报警,
                                    property:{type:bool},
                                    id:111,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:wr,
                                    code:Food_temp1_threshold,
                                    name:Probe A Threshold,
                                    property:{unit:,min:0,max:65535,scale:0,step:1,type:value},
                                    id:112,
                                    type:obj,
                                    desc:
                                },
                                {
                                    mode:wr,
                                    code:Food_temp2_threshold,
                                    name:Probe B Threshold,
                                    property:{unit:,min:0,max:65535,scale:0,step:1,type:value},
                                    id:113,
                                    type:obj,
                                    desc:
                                }
                            ],
                        schemaExt:[],
                        supportGroup:true,
                        switchDp:0,
                        ui:0000000167_,
                        uiConfig:{},
                        uiPhase:release,
                        uiType:RN,
                        verSw:1.0.0
                    }
                ],
                gwId:07200374b4e62d1b20dg,
                gwType:s,
                icon:smart/product_icon/kx.png,
                iconUrl:https://images.tuyaus.com/smart/product_icon/kx.png,
                isActive:true,
                isOnline:true,
                isShare:false,
                lat:,
                localKey:2a3c1a64ff1fca1g,
                lon:,
                name:Big Bear's Bull,
                pv:2.1,
                runtimeEnv:prod,
                time:1586140387,
                updateCacheTime:1586140459924,
                uuid:07200374b4e62d1b20dg,
                verSw:2.2.3
            }
        ]
    </string>
</map>
chansearrington commented 4 years ago

Installed NodeJS and NPM on ubuntu using: https://linuxize.com/post/how-to-install-node-js-on-ubuntu-18.04/

Installed TuyaCLI using: https://github.com/TuyaAPI/cli

Ran the test command from TuyaCLI to check if ID & Key were working: https://github.com/SDNick484/rectec_status/wiki/Device-ID-&-Key-Extraction

Set succeeded the grill turned on! woohoo!!!

chansearrington commented 4 years ago

@SDNick484 Not sure what's different, but I used this version of localtuya from @fastcolors instead of the version you pointed me to from @milesperhour and it worked.

No idea why.

https://github.com/fastcolors/localtuya-homeassistant

I'm going to try copying your rt.py over now and see if it still works.

chansearrington commented 4 years ago

@SDNick484 looks like we need to add a unique id to our config.

image

SDNick484 commented 4 years ago

I'll take a deeper look after work (at lunch now). I know the device only accepts one connection at a time (part of the reason I want to eventually move to MQTT). With that said, HA constantly reconnect so even if something was connected eventually, it retires.

I'm going to diff my switch.py on Hassio with my copy of it (rt.py in Github).

SDNick484 commented 4 years ago

Looks like the code was more different than I had expected; please try the revision of rt.py I just posted. Also as a heads up, I may switch this off to a separate project when I have time to be more organized.

Glad to hear the tuyapi stuff is working (very handy for debugging, and I may play around with some stuff later to learn Node better).

chansearrington commented 4 years ago

@SDNick484 Awesome! Looks like I now have the switch and the temp sensors!

image

chansearrington commented 4 years ago

Starting to look good.

I can turn it on/off and see the temps.

image

SDNick484 commented 4 years ago

Looks great! I'm working on getting the grill working with tuyamqtt now that the rewrite of python-tuya is supporting the older firmware.

drjared88 commented 3 years ago

This is awesome! Following this thread I was able to get my Rec Tec controller added to Home Assistant / Grafana.

I can see all my values and turn my grill on/off. Is there anyway at present to adjust the set temp?

Thanks!

SDNick484 commented 3 years ago

@drjared88 That's great to hear it worked for you. The Raspberry Pi that I was running Hassio off of had an issue with its microsd card so I've been off the platform for the last few months. I went ahead and re-installed Hassio on a new SD card tonight. I plan to take another look and will likely fork the Home Assistant work out to another project GitHub so stay tuned.

pdugas commented 3 years ago

It looks to me like I can find suitable uuid and localKey values in a file accessible on a non-rooted Android phone via USB/MTP from my Linux machine. I can find values in Phone/Android/data/com.ym.rectecgrill/cache/1.abj but when I punch them into the rectec_state.py script, it's not working for me. Can someone confirm the values in that file match the ones in the gw_storage.xml file?

pdugas commented 3 years ago

Woohoo!!! Turns out I have the newer firmware. It works using the tuya-cli command in #4. Question now is how to get pytua to use the 3.3 protocol...

pdugas commented 3 years ago
d = pytuya.OutletDevice(...)
d.set_version(3.3)

The rectec_state.py script is working for me with that change and the values from the 1.abj file on my non-rooted phone.

SDNick484 commented 3 years ago

Awesome, good debugging @pdugas. I still plan to get back to this, just had some personal stuff come up (although that's now wrapping up). Also dealing with Spare the Air days restricting my grilling due to CA fires.

pdugas commented 3 years ago

https://github.com/pdugas/recteq

This is working for me now.