jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
879 stars 159 forks source link

Setting 108 to true does not turn off the valve #357

Closed prgrobots closed 1 year ago

prgrobots commented 1 year ago

This issue is for the Holman WX1 WiFi hub with moisture sensor and wireless irrigation control valve.

I've been able to turn the valve on but have no idea why it won't turn off?

I turn it on with zigbee1.set_value('108', 'false') but setting it to true the same way doesn't turn it off. I've also tried to set 125, high moisture to true, setting the timer on 107 to 0 and setting 106 status to 0 for stop.

What am I missing?

My code is below, I am not running it in a loop, maybe thats it?


import tinytuya
import time
# Zigbee Gateway support uses a parent/child model where a parent gateway device is
#  connected and then one or more children are added.

# configure the parent device
#   address=None will cause it to search the network for the device
gw = tinytuya.Device( 'xxxxxxxxxxxx', address=None, local_key='xxxxxxxxxxxxxxxxxxxx', persist=True, version=3.3 )

print( 'GW IP found:', gw.address )

# configure one or more children.  Every dev_id must be unique!
#   cid is the "node_id" from devices.json
#   node_id can be used as an alias for cid
zigbee1 = tinytuya.OutletDevice( 'xxxxxxxxxxxx', cid='261', parent=gw )
zigbee2 = tinytuya.OutletDevice( 'xxxxxxxxxxxxxxxxx', cid='26B', parent=gw )
socket = tinytuya.OutletDevice('xxxxxxxxxxxxxxx', cid='26B', parent=gw)
print(zigbee1.status())
print('socket')
# print(socket.status())
print('')

zigbee1.set_value('108', 'false')
print('Air temp :',zigbee1.status()['dps']['101'])  
print('Soil moisture :',zigbee1.status()['dps']['102'])
print('Presence of soil sensor :',zigbee1.status()['dps']['115'])  
print('Irrigation, 1-run 0-stop 3-bypass :',zigbee1.status()['dps']['106'])
print('Minutes set for manual run:',zigbee1.status()['dps']['107'])
print('Delay to skip:',zigbee1.status()['dps']['113'])
print('Amount of water used last time:',zigbee1.status()['dps']['103'])
print('Pass high moisture:',zigbee1.status()['dps']['125'])
time.sleep(5)

# zigbee1.turn_on
# zigbee1.set_value('108', 'true')

# Generate the payload to send - add all the DPS values you want to change here
# payload=zigbee1.generate_payload(tinytuya.CONTROL, {108: 'false'})```
jasonacox commented 1 year ago

Hi @prgrobots - I recommend setting up a monitoring loop similar to the example code here: https://github.com/jasonacox/tinytuya/blob/master/examples/zigbee_gateway.py

https://github.com/jasonacox/tinytuya/blob/e1d0d50d26992ba8c8aa2c1968e7786ee73f3d43/examples/zigbee_gateway.py#L22-L34

Use the app to control the valve and notice which DPS values change. Mimic that with the set_value() calls.

uzlonewolf commented 1 year ago

'false' is a string and evaluates to True. Try zigbee1.set_value('108', False)

prgrobots commented 1 year ago

Thanks for the suggestion, I've re-tried that and the dps value at 108 (like you have previously said) is inverted. trying to turn off the valve with : zigbee1.set_value('108', 'true') or payload=zigbee1.generate_payload(tinytuya.CONTROL, {108: 'true'})

does not work.

Also, the example may need to be checked, shouldn't line 27: payload = gw.generate_payload(tinytuya.HEART_BEAT) be payload = zigbee1.generate_payload(tinytuya.HEART_BEAT) ?

uzlonewolf commented 1 year ago

If you need to set it to true then it should be zigbee1.set_value('108', True)

No, heartbeats are directed at the gateway to keep the TCP connection open, individual devices do not need them. Since those packets do not have a payload then sending them to a sub-device would still work however.

prgrobots commented 1 year ago

Ha! finally got it I had to use set_status zigbee1.set_status(on=False, switch=108, nowait=True) time.sleep(3) zigbee1.set_status(on=True, switch=108, nowait=True)