Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Repeated use of status() turns off light #29

Open
law1964 opened this issue Jun 28, 2018 · 9 comments
Open

Repeated use of status() turns off light #29

law1964 opened this issue Jun 28, 2018 · 9 comments

Comments

@law1964
Copy link

law1964 commented Jun 28, 2018

The light connected to my device starts in the ON (True) state.. I run the following python script:

import pytuya, time

old_state=[False, False, False]
SmartLife=["", "", ""]
SmartLife[1] = pytuya.OutletDevice('02200270ecfabc8e2ff0', '192.168.20.39', 'ceb9acd336c853f2')
SmartLife[2] = pytuya.OutletDevice('04200086b4e62d121b87', '192.168.20.14', '3e637e09ea909522') #Desk Lamp

device_set={2}
for i in device_set:
    data = SmartLife[i].status()
    old_state[i] = data['dps']['1']
    print ("*** Polling started " + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
        + " " + str(i) + " " + str(old_state[i]) )

while True:
    for i in device_set:
        data = SmartLife[i].status()
        state = data['dps']['1']
        if (state != old_state[i]):
            print time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()) + " State has changed to " + str(i) + " " + str(state)
            old_state[i]=state
        time.sleep(0.5)

The resulting console output:

*** Polling started Thu, 28 Jun 2018 10:18:46 2 True
Thu, 28 Jun 2018 10:48:33 State has changed to 2 False

There are no timers on the device. Nor is there user intervention. The light turns off by itself. This is repeatable (and an eventuality) on multiple but not all devices.

Thoughts?

@BillSobel
Copy link

BillSobel commented Jun 28, 2018 via email

@law1964
Copy link
Author

law1964 commented Jun 28, 2018

The device is in an ON state before the script is executed.
I don't know how to answer your question because I don't know what a timer DP is. Please elaborate.
As far as I know, no other device affecting processes are running and nobody else touches the device except me.

@BillSobel
Copy link

BillSobel commented Jun 28, 2018 via email

@law1964
Copy link
Author

law1964 commented Jun 28, 2018

Thanks for the explanation.
I used Alexa to turn on the light by saying "Alexa, turn on Desk Lamp" in the first place. Alexa would not set a countdown DP value.

@clach04
Copy link
Owner

clach04 commented Jun 29, 2018

@law1964 as @BillSobel said this sounds more like a timer (or another device). Like you I'm using Alex (with a skill using the cloud API, I'm not using a HA skill) and I'm not seeing this, I just tried you test code and I'm not seeing this.

Thoughts;

  • how many iterations/secs does it take for this to happen for you?
  • can you dump data['dps'] in your script before the if? If a timer is set, element 2 will be non-zero - this number does NOT change until the timer expires - or at least that's what I see with my devices ;-) - this would at least help prove/disprove the timer theory

@law1964
Copy link
Author

law1964 commented Jun 29, 2018

I see that you changed the Alexa to the masculine form. I hope the operation went smoothly. :)

The following is the relevant portions of the data dump:

*** Polling started Fri, 29 Jun 2018 07:55:03 2 True
{u'1': True}
{u'1': True}
{u'1': True}
{u'1': True}
.
.
{u'1': True}
{u'1': True}
{u'1': True}
{u'1': True}
{u'1': False}
Fri, 29 Jun 2018 07:59:18 State has changed to 2 False
counter = 456
{u'1': False}
{u'1': False}

It took 456 iterations this time, but it varies. The print data['dps'] right before the if statement in the script shows that there is only one element.

It just twigged that dps could stand for "double pole switch". I was wondering what the acronym stood for...

I'm also wondering whether something is making the device reset. That would explain why it changes to False (OFF) and never to True (ON) while the program is running. I have also noticed that there is a small delay (a few seconds) before I get the message that the state has changed. Is there any way that I can test this?

@law1964
Copy link
Author

law1964 commented Jun 29, 2018

I ran the test program a second time. It took longer the time for the light to turn off, about 27 minutes and 2963 iterations. There is definitely a delay between when the light turns off and when the program detects the change (see sample points in bold). At most, the delay should only be a second.

*** Polling started Fri, 29 Jun 2018 08:27:50 2 True
Fri, 29 Jun 2018 08:27:50
{u'1': True}
Fri, 29 Jun 2018 08:27:51
{u'1': True}
.
.
Fri, 29 Jun 2018 08:54:43
{u'1': True}
Fri, 29 Jun 2018 08:54:43
{u'1': True}
Fri, 29 Jun 2018 08:54:44
{u'1': True}
Fri, 29 Jun 2018 08:54:52
{u'1': False}

Fri, 29 Jun 2018 08:54:52 State has changed to 2 False
counter = 2963

@jchulce
Copy link

jchulce commented Nov 28, 2018

I have two plugs impacted by this issue. They blink on and off by themselves several times an hour. I use pytuya via tuya-homeassistant. The impacted plugs are https://www.amazon.com/EPICKA-WiFi-Smart-Plug-2-Pack/dp/B076HKHSSX/ "EPICKA WiFi Smart Plug Mini (2-Pack) - Wireless Smart Plug Socket Outlet, Compatible with Amazon Alexa and Google Assistant, No Hub Required, Remote Control Your Devices from Anywhere". These are marked with model WP1000 model: SM-PW702 FCCID:2AJ5F. I have many other tuya plugs with different brands that work just fine, it's just that one model having the issue for me. I started using https://github.com/tixi/python-tuya-experimental earlier this week and have had issues since. Seems that persistent connections makes the issue go away.

@aneisch
Copy link

aneisch commented Dec 31, 2018

Issue still persists it appears but only for some devices. Perhaps this is a firmware bug in particular Tuya devices/versions?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants