NickWaterton / eWeLink-mqtt

Bridge to control Sonoff Devices via MQTT
MIT License
19 stars 5 forks source link

Set receive interval #4

Closed ManuelBu96 closed 1 year ago

ManuelBu96 commented 1 year ago

Hi,

thank you for your programming. Is it possible to set a receiving interval so that the software ask for new data each 10 seconds for example? I've already tried the poll function, but it doesn't work. To get new data I always have to restart the service.

The device is a PowSwitch with the model PSF-X67 Thanks in advance for your help.

NickWaterton commented 1 year ago

The bridge just subscribes to the eWeLink websocket stream. This is a real time data feed - any new data received is automatically converted to mqtt topics and pushed to the broker.

With a PowSwitch, this is every time the values change, every few minutes or so.

Can you post the command line you are using?

ManuelBu96 commented 1 year ago

Did you mean the value change of the off/on switch?

The command is the following: python3.8 ./ewelink.py mail password -r eu -b iobroker(mqtt Server) -U username -P password -l ./sonoff.log -D

NickWaterton commented 1 year ago

No, it will read everything, if your device type is set correctly (which it may not be).

Can you post the text (using code fences please) of the log file when you run the command line, then operate the switch.

Thanks.

ManuelBu96 commented 1 year ago

Sorry for the late reply. Here is the code when turning the switch on and off.

[2022-09-30 20:00:06,077][DEBUG](Main.EwelinkClient  ) RECEIVED cloud msg: {
  "action": "update",
  "apikey": "e475e0bf-ce4d-4e69-9678-b045b80e3628",
  "deviceid": "10016945f7",
  "from": "device",
  "params": {
    "switch": "off"
  },
  "seq": "1202",
  "sequence": "1664560805478",
  "userAgent": "device"
}
[2022-09-30 20:00:06,077][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/json: {"action": "update", "deviceid": "10016945f7", "apikey": "e475e0bf-ce4d-4e69-9678-b045b80e3628", "userAgent": "device", "sequence": "1664560805478", "params": {"switch": "off"}, "from": "device", "seq": "1202"}
[2022-09-30 20:00:06,077][DEBUG](Main.Default        ) Received data {'action': 'update', 'deviceid': '10016945f7', 'apikey': 'e475e0bf-ce4d-4e69-9678-b045b80e3628', 'userAgent': 'device', 'sequence': '1664560805478', 'params': {'switch': 'off'}, 'from': 'device', 'seq': '1202'}
[2022-09-30 20:00:06,077][DEBUG](Main.Default        ) Action Update: Publishing: {'switch': 'off'}
[2022-09-30 20:00:06,077][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/switch: off
[2022-09-30 20:00:06,078][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/last_update: Fri Sep 30 20:00:06 2022
[2022-09-30 20:00:06,078][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/status: OK
[2022-09-30 20:00:13,725][DEBUG](Main.EwelinkClient  ) Waiting...
[2022-09-30 20:00:16,800][DEBUG](Main.EwelinkClient  ) RECEIVED cloud msg: {
  "action": "update",
  "apikey": "e475e0bf-ce4d-4e69-9678-b045b80e3628",
  "deviceid": "10016945f7",
  "from": "device",
  "params": {
    "switch": "on"
  },
  "seq": "1203",
  "sequence": "1664560816236",
  "userAgent": "device"
}
[2022-09-30 20:00:16,801][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/json: {"action": "update", "deviceid": "10016945f7", "apikey": "e475e0bf-ce4d-4e69-9678-b045b80e3628", "userAgent": "device", "sequence": "1664560816236", "params": {"switch": "on"}, "from": "device", "seq": "1203"}
[2022-09-30 20:00:16,801][DEBUG](Main.Default        ) Received data {'action': 'update', 'deviceid': '10016945f7', 'apikey': 'e475e0bf-ce4d-4e69-9678-b045b80e3628', 'userAgent': 'device', 'sequence': '1664560816236', 'params': {'switch': 'on'}, 'from': 'device', 'seq': '1203'}
[2022-09-30 20:00:16,801][DEBUG](Main.Default        ) Action Update: Publishing: {'switch': 'on'}
[2022-09-30 20:00:16,801][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/switch: on
[2022-09-30 20:00:16,801][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/last_update: Fri Sep 30 20:00:16 2022
[2022-09-30 20:00:16,801][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/status: OK
NickWaterton commented 1 year ago

I need the output when you run the command line, so I can see what kind of device it's registering as, not when you switch it.

Ie ./ewelink.py mail password -r eu -b iobroker(mqtt Server) -U username -P password -l ./sonoff.log -D

Run the command line with the -D option (debug), and post the whole output.

Once I know what device type is is reporting, it should be an easy fix.

ManuelBu96 commented 1 year ago

Ok then I misunderstood your message. Here's the right one.

[2022-10-01 09:59:26,664][DEBUG](Main.EwelinkClient  ) Devices: [
  {
    "apikey": "***",
    "brandLogo": "",
    "brandName": "coolkit",
    "devConfig": {
      "timerCount": "16/28"
    },
    "devGroups": [],
    "deviceFeature": {},
    "deviceid": "10016945f7",
    "devicekey": "***",
    "extra": {
      "apmac": "d0:27:02:d2:89:3f",
      "brandId": "59e0dbc25c1af3a660cc1ac0",
      "chipid": "00AE689D",
      "description": "2022\u5e742\u670824\u65e5 \u84b2\u7396\u4e91 WW220064",
      "mac": "d0:27:02:d2:89:3e",
      "manufacturer": "\u6df1\u5733\u9177\u5b85\u79d1\u6280\u6709\u9650\u516c\u53f8",
      "model": "PSF-B67-GL",
      "modelInfo": "5ae946f8583ae7fb0c3e5a69",
      "staMac": "4C:EB:D6:AE:68:9D",
      "ui": "\u529f\u7387\u68c0\u6d4b\u63d2\u5ea7\u8fc7\u8f7d\u544a\u8b66",
      "uiid": 32
    },
    "family": {
      "familyid": "632ad6c23c8b4e00093bf1eb",
      "index": 0,
      "members": []
    },
    "isSupportGroup": false,
    "isSupportedOnMP": true,
    "name": "Device6945f7",
    "online": true,
    "params": {
      "alarmCValue": [
        -1,
        -1
      ],
      "alarmPValue": [
        -1,
        -1
      ],
      "alarmType": "pcv",
      "alarmVValue": [
        -1,
        -1
      ],
      "bindInfos": {},
      "bssid": "00:00:00:00:00:00",
      "current": "0.18",
      "demNextFetchTime": 1664575200000,
      "endTime": "2022-09-21T16:54:38.872Z",
      "fwVersion": "3.5.0",
      "hundredDaysKwh": "get",
      "init": 1,
      "oneKwh": "stop",
      "power": "5.35",
      "pulse": "off",
      "pulseWidth": 500,
      "rssi": -60,
      "sledOnline": "on",
      "ssid": "****",
      "staMac": "4C:EB:D6:AE:68:9D",
      "startTime": "2022-09-21T16:54:33.198Z",
      "startup": "off",
      "switch": "on",
      "timeZone": 2,
      "uiActive": 60,
      "version": 8,
      "voltage": "223.73"
    },
    "productModel": "PSF-X67",
    "settings": {
      "alarmNotify": 1,
      "appDoorbellNotify": 1,
      "opsHistory": 1,
      "opsNotify": 0,
      "wxAlarmNotify": 0,
      "wxDoorbellNotify": 0,
      "wxOpsNotify": 0
    },
    "shareTo": [],
    "showBrand": false,
    "tags": {
      "m_3628_info": "on"
    }
  }
]
[2022-10-01 09:59:26,665][DEBUG](Main.Default        ) adding bindInfos to settings
[2022-10-01 09:59:26,665][DEBUG](Main.Default        ) adding version to settings
[2022-10-01 09:59:26,665][DEBUG](Main.Default        ) adding ssid to settings
[2022-10-01 09:59:26,665][DEBUG](Main.Default        ) adding bssid to settings
[2022-10-01 09:59:26,665][DEBUG](Main.Default        ) adding pulse to settings
[2022-10-01 09:59:26,665][DEBUG](Main.Default        ) adding pulseWidth to settings
[2022-10-01 09:59:26,665][DEBUG](Main.Default        ) adding uiActive to settings
[2022-10-01 09:59:26,666][DEBUG](Main.Default        ) Created PowSwitch Device V:1.0, model: PSF-X67
[2022-10-01 09:59:26,666][ INFO](Main.EwelinkClient  ) Created instance of Device: PowSwitch, model: PSF-X67 for: 1001693463 (Device693463)
[2022-10-01 09:59:26,666][DEBUG](Main.Default        ) adding demNextFetchTime to settings
[2022-10-01 09:59:26,666][DEBUG](Main.Default        ) Created PowSwitch Device V:1.0, model: PSF-X67
[2022-10-01 09:59:26,666][ INFO](Main.EwelinkClient  ) Created instance of Device: PowSwitch, model: PSF-X67 for: 10016945f7 (Device6945f7)
[2022-10-01 09:59:26,675][DEBUG](Main.Default        ) Received data {'name': 'Device6945f7', 'deviceid': '***', 'apikey': '***', 'extra': {'uiid': 32, 'description': '2022年2月24日 蒲玖云 WW220064', 'brandId': '59e0dbc25c1af3a660cc1ac0', 'apmac': 'd0:27:02:d2:89:3f', 'mac': 'd0:27:02:d2:89:3e', 'ui': '功率检测插座过载告警', 'modelInfo': '5ae946f8583ae7fb0c3e5a69', 'model': 'PSF-B67-GL', 'manufacturer': '深圳酷宅科技有限公司', 'chipid': '00AE689D', 'staMac': '4C:EB:D6:AE:68:9D'}, 'brandName': 'coolkit', 'brandLogo': '', 'showBrand': False, 'productModel': 'PSF-X67', 'tags': {'m_3628_info': 'on'}, 'devConfig': {'timerCount': '16/28'}, 'settings': {'opsNotify': 0, 'opsHistory': 1, 'alarmNotify': 1, 'wxAlarmNotify': 0, 'wxOpsNotify': 0, 'wxDoorbellNotify': 0, 'appDoorbellNotify': 1}, 'devGroups': [], 'family': {'familyid': '632ad6c23c8b4e00093bf1eb', 'index': 0, 'members': []}, 'shareTo': [], 'devicekey': '***', 'online': True, 'params': {'bindInfos': {}, 'version': 8, 'sledOnline': 'on', 'ssid': '***', 'bssid': '00:00:00:00:00:00', 'fwVersion': '3.5.0', 'staMac': '4C:EB:D6:AE:68:9D', 'rssi': -60, 'init': 1, 'alarmType': 'pcv', 'alarmVValue': [-1, -1], 'alarmCValue': [-1, -1], 'alarmPValue': [-1, -1], 'switch': 'on', 'startup': 'off', 'pulse': 'off', 'pulseWidth': 500, 'power': '5.35', 'voltage': '223.73', 'current': '0.18', 'oneKwh': 'stop', 'uiActive': 60, 'timeZone': 2, 'hundredDaysKwh': 'get', 'demNextFetchTime': 1664575200000, 'endTime': '2022-09-21T16:54:38.872Z', 'startTime': '2022-09-21T16:54:33.198Z'}, 'isSupportGroup': False, 'isSupportedOnMP': True, 'deviceFeature': {}}
[2022-10-01 09:59:26,675][DEBUG](Main.Default        ) Params Update: Publishing: {'bindInfos': {}, 'version': 8, 'sledOnline': 'on', 'ssid': '***', 'bssid': '00:00:00:00:00:00', 'fwVersion': '3.5.0', 'staMac': '4C:EB:D6:AE:68:9D', 'rssi': -60, 'init': 1, 'alarmType': 'pcv', 'alarmVValue': [-1, -1], 'alarmCValue': [-1, -1], 'alarmPValue': [-1, -1], 'switch': 'on', 'startup': 'off', 'pulse': 'off', 'pulseWidth': 500, 'power': '5.35', 'voltage': '223.73', 'current': '0.18', 'oneKwh': 'stop', 'uiActive': 60, 'timeZone': 2, 'hundredDaysKwh': 'get', 'demNextFetchTime': 1664575200000, 'endTime': '2022-09-21T16:54:38.872Z', 'startTime': '2022-09-21T16:54:33.198Z'}
[2022-10-01 09:59:26,675][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/bindInfos: {}
[2022-10-01 09:59:26,675][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/version: 8
[2022-10-01 09:59:26,676][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/sledOnline: on
[2022-10-01 09:59:26,676][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/ssid: ***
[2022-10-01 09:59:26,676][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/bssid: 00:00:00:00:00:00
[2022-10-01 09:59:26,676][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/fwVersion: 3.5.0
[2022-10-01 09:59:26,676][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/staMac: 4C:EB:D6:AE:68:9D
[2022-10-01 09:59:26,676][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/rssi: -60
[2022-10-01 09:59:26,677][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/init: 1
[2022-10-01 09:59:26,677][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/alarmType: pcv
[2022-10-01 09:59:26,677][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/alarmVValue: [-1, -1]
[2022-10-01 09:59:26,677][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/alarmCValue: [-1, -1]
[2022-10-01 09:59:26,677][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/alarmPValue: [-1, -1]
[2022-10-01 09:59:26,678][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/switch: on
[2022-10-01 09:59:26,678][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/startup: off
[2022-10-01 09:59:26,678][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/pulse: off
[2022-10-01 09:59:26,678][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/pulseWidth: 500
[2022-10-01 09:59:26,678][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/power: 5.35
[2022-10-01 09:59:26,678][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/voltage: 223.73
[2022-10-01 09:59:26,679][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/current: 0.18
[2022-10-01 09:59:26,679][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/oneKwh: stop
[2022-10-01 09:59:26,679][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/uiActive: 60
[2022-10-01 09:59:26,679][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/timeZone: 2
[2022-10-01 09:59:26,679][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/hundredDaysKwh: get
[2022-10-01 09:59:26,679][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/demNextFetchTime: 1664575200000
[2022-10-01 09:59:26,680][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/endTime: 2022-09-21T16:54:38.872Z
[2022-10-01 09:59:26,680][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/startTime: 2022-09-21T16:54:33.198Z
[2022-10-01 09:59:26,680][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/last_update: Sat Oct  1 09:59:26 2022
NickWaterton commented 1 year ago

Ok, thanks,

It seems to be registering correctly - there is nothing I can fix.

I just report what the device sends. If it doesn't send anything, there is not much I can do.

My PowSwitch devices report power every minute or so.

Maybe there is a setting in the eWeApp that sets when these switches report - either a time interval, or minimum change required for them to report.

ManuelBu96 commented 1 year ago

Ok I see if the App is open the Values are updated.

[2022-10-03 16:29:44,257][DEBUG](Main.EwelinkClient  ) RECEIVED cloud msg: {
  "action": "update",
  "apikey": "e475e0bf-ce4d-4e69-9678-b045b80e3628",
  "deviceid": "10016945f7",
  "from": "device",
  "params": {
    "current": "0.18",
    "power": "5.44",
    "voltage": "226.90"
  },
  "userAgent": "device"
}
[2022-10-03 16:29:44,257][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/json: {"action": "update", "deviceid": "10016945f7", "apikey": "e475e0bf-ce4d-4e69-9678-b045b80e3628", "userAgent": "device", "params": {"power": "5.44", "voltage": "226.90", "current": "0.18"}, "from": "device"}
[2022-10-03 16:29:44,257][DEBUG](Main.Default        ) Received data {'action': 'update', 'deviceid': '10016945f7', 'apikey': 'e475e0bf-ce4d-4e69-9678-b045b80e3628', 'userAgent': 'device', 'params': {'power': '5.44', 'voltage': '226.90', 'current': '0.18'}, 'from': 'device'}
[2022-10-03 16:29:44,257][DEBUG](Main.Default        ) Action Update: Publishing: {'power': '5.44', 'voltage': '226.90', 'current': '0.18'}
[2022-10-03 16:29:44,257][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/power: 5.44
[2022-10-03 16:29:44,258][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/voltage: 226.90
[2022-10-03 16:29:44,258][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/current: 0.18
[2022-10-03 16:29:44,258][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/last_update: Mon Oct  3 16:29:44 2022
[2022-10-03 16:29:44,258][ INFO](Main.MQTT           ) publishing item: /ewelink_status/10016945f7/status: OK

Is there a way to send the update action without the open app?

NickWaterton commented 1 year ago

You can try sending a get_config command to the device. eg: /ewelink_command/10016945f7get_config

I'm not sure if that will just fetch the existing numbers, or get new ones from the device.

ManuelBu96 commented 1 year ago

Ok I will try this at the weekend, when I am back from work.

ManuelBu96 commented 1 year ago

Ok I get a workaround by restarting the service every x seconds. I will switch to antoher component soon.