diff --git a/automations/temperature.yaml b/automations/temperature.yaml index 337634c..2447be4 100644 --- a/automations/temperature.yaml +++ b/automations/temperature.yaml @@ -85,7 +85,6 @@ - alias: 主卧温度变化-调控空调 mode: restart - initial_state: false trigger: - platform: time at: '21:00:01' @@ -101,8 +100,8 @@ - service: zhiact.actuate data: sensor_id: sensor.zhu_wo_wen_du - sensor_values: [28, 28.5] - alt_sensor_values: [28.5, 29] + sensor_values: [28.5, 29] + alt_sensor_values: [29, 29.5] # sensor_id: climate.zhu_wo_kong_diao # sensor_attr: current_temperature # sensor_values: [29, 30, 31, 32, 33] @@ -114,7 +113,6 @@ - alias: 儿童房温度变化-调控空调 mode: restart - initial_state: false trigger: - platform: time at: '21:00:01' @@ -130,8 +128,8 @@ - service: zhiact.actuate data: sensor_id: sensor.er_tong_fang_wen_du - sensor_values: [22.5, 23, 23.5, 24, 24.5] - alt_sensor_values: [24, 24.5, 25, 25.5, 26] + sensor_values: [23, 23.2, 23.5, 24, 24.5] + alt_sensor_values: [23.5, 24, 24.5, 25, 25.5] # sensor_id: climate.er_tong_fang_kong_diao # sensor_attr: current_temperature # sensor_values: [29, 30, 31, 32, 33] @@ -191,7 +189,6 @@ - alias: 儿童房温度变化-调控风扇 mode: restart - initial_state: false trigger: - platform: time at: '20:00:01' @@ -215,7 +212,6 @@ - alias: 主卧温度变化-调控风扇 mode: restart - initial_state: false trigger: - platform: time at: '20:00:01' diff --git a/extras/test/test_modbus.py b/extras/test/test_modbus.py index 83ee5e4..a74db04 100755 --- a/extras/test/test_modbus.py +++ b/extras/test/test_modbus.py @@ -1,34 +1,40 @@ #!/usr/bin/env python3 import struct -from pymodbus.client.sync import ModbusTcpClient as ModbusClient -from pymodbus.transaction import ModbusRtuFramer as ModbusFramer +from pymodbus.client import ModbusTcpClient +from pymodbus.transaction import ModbusRtuFramer -import socket -s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -s.settimeout(5) -s.connect(('192.168.1.60', 8899)) -s.sendall(b'\x55\xAA\x55\x00\x25\x80\x03\xA8') # For USR initialize -s.close() +HOST = '192.168.1.60' +PORT = 8899 +def reset(host, port): + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(5) + s.connect((host, port)) + s.sendall(b'\x55\xAA\x55\x00\x25\x80\x03\xA8') # For USR initialize + s.close() + ATTR_MAP = { - 'temperature': {'registers': [3, 6, 9, 12], 'register_type': 'input'}, 'target_temp': {'registers': [4, 8, 12, 16]}, + 'temperature': {'registers': [3, 6, 9, 12], 'register_type': 'input'}, 'operation': {'registers': [5, 9, 13, 17]}, 'fan_mode': {'registers': [6, 10, 14, 18]}, 'state_is_on': {'registers': [1, 2, 3, 4], 'register_type': 'coil'} } -client = ModbusClient(host='192.168.1.60', port=8899, framer=ModbusFramer) +#reset(HOST, PORT) + +client = ModbusTcpClient(host=HOST, port=PORT, framer=ModbusRtuFramer) kwargs = {'unit': 1} +ret = client.connect() -for key in ATTR_MAP: - dict = ATTR_MAP[key] - print("%s:\t" % key, end='') - for register in dict['registers']: - register_type = dict.get('register_type') +for k, v in ATTR_MAP.items(): + print("%s:\t" % k, end='') + for register in v['registers']: + register_type = v.get('register_type') if register_type == 'coil': result = client.read_coils(register, 1, **kwargs) value = bool(result.bits[0]) @@ -36,9 +42,11 @@ if register_type == 'input': result = client.read_input_registers(register, 1, **kwargs) else: - result = client.read_holding_registers(register, 1, **kwargs) - byte_string = b''.join([x.to_bytes(2, byteorder='big') - for x in result.registers]) + result = client.read_holding_registers(register) + if isinstance(result, Exception): + print("Exception: %s" % result) + continue + byte_string = b''.join([x.to_bytes(2, byteorder='big') for x in result.registers]) value = struct.unpack('>H', byte_string)[0] print("%s\t" % value, end='') print("")