AlexxIT / SonoffLAN

Control Sonoff Devices with eWeLink (original) firmware over LAN and/or Cloud from Home Assistant
https://github.com/AlexxIT/Blog
MIT License
2.7k stars 414 forks source link

Sonoff TH10 with sensor MS01 soil moisture sensor humidity value not populating to HA 2021.9.7 #603

Closed peterhoe closed 2 years ago

peterhoe commented 3 years ago

Am having some troubles integrating the Sonoff MS01 soil moisture sensor using a TH10

Sonoff LAN v2.4.6

Works fine with AM2301 temp / humidity sensor

 'sensorType': 'AM2301', 'currentHumidity': '29', 'currentTemperature': '34.1',

2021-10-03 13:00:27  DEBUG    sonoff_local  1001191bb3 <= Local3 | {'mainSwitch': '', 'deviceType': 'normal', 'switch': 'on', 'startup': 'stay', 'pulse': 'off', 'pulseWidth': 500, 'sledOnline': 'on', 'sensorType': 'AM2301', 'currentHumidity': '29', 'currentTemperature': '34.2', 'ssid': '...', 'bssid': '...'} | 3

Hass State attributes with AM2301 manufacturer: SONOFF model: TH10 sw_version: PSA-BHA-GL v3.5.0 cloud: online rssi: -41 local: online humidity: 29 temperature: 33.5 friendly_name: irr-balcony-soil

MS01 with TH10 will not pull in humidity sensor data to Haasio, however in Sonoff debug i see a value for currentHumidity although currentTemperature is listed as unavailable

 'sensorType': 'MS01', 'currentHumidity': '19', 'currentTemperature': 'unavailable', 

2021-10-03 12:45:09  DEBUG    main          Init force_update for attributes: {'humidity'}
2021-10-03 12:45:09  DEBUG    main          Init auto sensors for: ['humidity', 'temperature', 'power', 'current', 'voltage']
2021-10-03 12:45:09  DEBUG    main          1001191bb3 == Init   | {'uiid': 15, 'extra': {'manufacturer': 'SONOFF', 'model': 'TH10', 'sw_version': 'PSA-BHA-GL v3.5.0'}, 'params': {'version': 8, 'sledOnline': 'on', 'init': 1, 'switch': 'on', 'fwVersion': '3.5.0', 'rssi': -37, 'staMac': '...', 'startup': 'stay', 'pulse': 'off', 'pulseWidth': 500, 'sensorType': 'MS01', 'currentHumidity': '19', 'currentTemperature': 'unavailable', 'deviceType': 'normal', 'only_device': {'ota': 'success'}, 'mainSwitch': '', 'ssid': '...', 'bssid': '...', 'cloud': 'online'}}

Hass State attributes with MS01 manufacturer: SONOFF model: TH10 sw_version: PSA-BHA-GL v3.5.0 cloud: online rssi: -36 local: online friendly_name: irr-balcony-soil

langejos commented 3 years ago

I'm also playing around with a TH10 and the new MS01 soil moisture sensor (having hoped it would maybe use the existing humidity sensor), but can't seem to get it to work. Will it need a new development for extending the available sensors to include moisture?

Thank you!

Ih8rain2 commented 2 years ago

I have been playing around with the MS01 as well but I can’t pull any reading to HA. It would be very nice if this could be added. Would save the world probably quite some water 😁 Used TH10 + ms01

This my debug log. I can’t find any differences between various set-ups.

Sensor MS01:

2021-12-25 02:48:42  DEBUG    main          1000bcd3c2 == Init   | {'uiid': 15, 'extra': {'manufacturer': 'SONOFF', 'model': 'TH10', 'sw_version': 'PSA-BHA-GL v3.5.0'}, 'params': {'bindInfos': {'gaction': ['...', '...'], 'alexa': ['...']}, 'version': 8, 'sledOnline': 'on', 'init': 1, 'switch': 'on', 'fwVersion': '3.5.0', 'rssi': -42, 'staMac': '...', 'startup': 'off', 'pulse': 'off', 'pulseWidth': 500, 'deviceType': 'normal', 'mainSwitch': 'on', 'sensorType': 'MS01', 'currentHumidity': '25', 'currentTemperature': 'unavailable', 'timers': [{'mId': '...', 'type': 'repeat', 'at': '0 3 * * 0,1,2,3,4,5,6', 'coolkit_timer_type': 'repeat', 'enabled': 1, 'do': {'switch': 'off', 'mainSwitch': 'off'}}], 'only_device': {'ota': 'success'}, 'ssid': '...', 'bssid': '...', 'cloud': 'online'}}

2021-12-25 02:48:43  DEBUG    sonoff_local  1000bcd3c2 <= Local1 | {'mainSwitch': 'on', 'deviceType': 'normal', 'switch': 'on', 'startup': 'off', 'pulse': 'off', 'pulseWidth': 500, 'sledOnline': 'on', 'sensorType': 'MS01', 'currentHumidity': '25', 'currentTemperature': 'unavailable', 'ssid': '...', 'bssid': '...'} | 22

Sensor AM2301:

2021-12-25 03:34:11  DEBUG    main          1000bcd3c2 == Init   | {'uiid': 15, 'extra': {'manufacturer': 'SONOFF', 'model': 'TH10', 'sw_version': 'PSA-BHA-GL v3.5.0'}, 'params': {'bindInfos': {'gaction': ['...', '...'], 'alexa': ['...']}, 'version': 8, 'sledOnline': 'on', 'init': 1, 'switch': 'on', 'fwVersion': '3.5.0', 'rssi': -42, 'staMac': '...', 'startup': 'off', 'pulse': 'off', 'pulseWidth': 500, 'deviceType': 'normal', 'mainSwitch': 'on', 'sensorType': 'AM2301', 'currentHumidity': '65', 'currentTemperature': '23.9', 'timers': [{'mId': '...', 'type': 'repeat', 'at': '0 3 * * 0,1,2,3,4,5,6', 'coolkit_timer_type': 'repeat', 'enabled': 1, 'do': {'switch': 'off', 'mainSwitch': 'off'}}], 'only_device': {'ota': 'success'}, 'ssid': '...', 'bssid': '...', 'cloud': 'online'}}

2021-12-25 03:34:12  DEBUG    sonoff_local  1000bcd3c2 <= Local1 | {'mainSwitch': 'on', 'deviceType': 'normal', 'switch': 'on', 'startup': 'off', 'pulse': 'off', 'pulseWidth': 500, 'sledOnline': 'on', 'sensorType': 'AM2301', 'currentHumidity': '64', 'currentTemperature': '24.0', 'ssid': '...', 'bssid': '...'} | 7

Sensor DS18B20:

2021-12-25 04:15:17  DEBUG    main          1000bedaf2 == Init   | {'uiid': 15, 'extra': {'manufacturer': 'SONOFF', 'model': 'TH16', 'sw_version': 'PSA-BHA-GL v3.5.0'}, 'params': {'bindInfos': {'gaction': ['...', '...'], 'alexa': ['...']}, 'version': 8, 'sledOnline': 'on', 'init': 1, 'switch': 'off', 'fwVersion': '3.5.0', 'rssi': -24, 'staMac': '...', 'startup': 'off', 'pulse': 'off', 'pulseWidth': 500, 'sensorType': 'DS18B20', 'currentHumidity': 'unavailable', 'currentTemperature': '12.9', 'mainSwitch': '', 'deviceType': 'normal', 'only_device': {'ota': 'success'}, 'ssid': '...', 'bssid': '...', 'cloud': 'online'}}

It seems that in case of MS01 the attributes are not added. I have explored sensor.py but I haven’t found the clue. When using the MS01 the attributes temperature and humidity are not available. But when the AM2301 is connected it comes back after restart. Tested this twice. Swapping one the AM2301 to MS01 and back make the attributes and values to disappear and appear again. Why is that? I need a few clues or pointers where to look to resolve this.. Alexxit?

I have resolved it. Works for me now. I have sent the info to Alex.

Actually I think it’s/was a bug

ghkaan commented 2 years ago

Tried to get soil humidity data but without any success too (TH16+MS01).

jorgeconduto commented 2 years ago

me 2, why MS01+TH16 dont work? :(

jorgeconduto commented 2 years ago

share your solution my friend :)

Ih8rain2 commented 2 years ago

In the following function in cloud.py there is a mistake. Replace the existing 'def fix_attrs(deviceid: str, state: dict)' by this one and let me know if it worked for you: ""

try:

    # battery_level is common name for battery attribute
    if 'battery' in state:
        state[ATTR_BATTERY_LEVEL] = state['battery']

    for k in ('power', 'voltage', 'current'):
        if k in state:
            state[k] = float(state[k])

    # zigbee device
    if deviceid.startswith('a4'):
        for k in ('temperature', 'humidity'):
            if k in state:
                state[k] = int(state[k]) / 100.0        

    # "unavailable" in state creates a fault
    if state['currentHumidity'] == 'unavailable':
        _LOGGER.debug(f"TH humidity: unavailable")
    elif 'currentHumidity' in state:
        state['humidity'] = float(state['currentHumidity'])
        _LOGGER.debug(f"TH humidity: {state['humidity']}")
    if state['currentTemperature'] == 'unavailable':
        _LOGGER.debug(f"TH temperature: unavailable")
    elif 'currentTemperature' in state:
        state['temperature'] = float(state['currentTemperature'])
        _LOGGER.debug(f"TH temperature: {state['temperature']}")

except:
    pass

""

Good luck

ghkaan commented 2 years ago

In the following function in cloud.py there is a mistake. Replace the existing 'def fix_attrs(deviceid: str, state: dict)' by this one and let me know if it worked for you: ""


    # "unavailable" in state creates a fault
    if state['currentHumidity'] == 'unavailable':
        _LOGGER.debug(f"TH humidity: unavailable")
    elif 'currentHumidity' in state:
        state['humidity'] = float(state['currentHumidity'])
        _LOGGER.debug(f"TH humidity: {state['humidity']}")
    if state['currentTemperature'] == 'unavailable':
        _LOGGER.debug(f"TH temperature: unavailable")
    elif 'currentTemperature' in state:
        state['temperature'] = float(state['currentTemperature'])
        _LOGGER.debug(f"TH temperature: {state['temperature']}")

Thanks a lot - yes, this part helps!

Ih8rain2 commented 2 years ago

Great to hear !

Groenbaard commented 2 years ago

Also worked for me thank you very much :-)

jorgeconduto commented 2 years ago

Hi, i changed my code for, custom_components/sonoff/sonoff_cloud.py

def fix_attrs(deviceid: str, state: dict):
    """
    - Sonoff TH `currentTemperature: "24.7"`
    - Sonoff TH `currentTemperature: "unavailable"`
    - Sonoff ZigBee: `temperature: "2096"`
    - Sonoff SC: `temperature: 23`
    - Sonoff POW: `power: "12.78"`
    """
    try:

        # battery_level is common name for battery attribute
        if 'battery' in state:
            state[ATTR_BATTERY_LEVEL] = state['battery']

        for k in ('power', 'voltage', 'current'):
            if k in state:
                state[k] = float(state[k])

        # zigbee device
        if deviceid.startswith('a4'):
            for k in ('temperature', 'humidity'):
                if k in state:
                    state[k] = int(state[k]) / 100.0        

        # "unavailable" in state creates a fault
        if state['currentHumidity'] == 'unavailable':
            _LOGGER.debug(f"TH humidity: unavailable")
        elif 'currentHumidity' in state:
            state['humidity'] = float(state['currentHumidity'])
            _LOGGER.debug(f"TH humidity: {state['humidity']}")
        if state['currentTemperature'] == 'unavailable':
            _LOGGER.debug(f"TH temperature: unavailable")
        elif 'currentTemperature' in state:
            state['temperature'] = float(state['currentTemperature'])
            _LOGGER.debug(f"TH temperature: {state['temperature']}")

    except:
        pass

add: configuration.yaml

sonoff:
  username: x@x.com
  password: x
  force_update: [temperature, power]
  scan_interval: "00:01:00"
  reload: always
  sensors: [temperature, humidity, power, current, voltage]

validate config, reboot and not working :(

Ih8rain2 commented 2 years ago

You just did a copy-paste? And not working means the sensor doesn´t appear? or the sensor appears but doesnt give values?

jorgeconduto commented 2 years ago

You just did a copy-paste? And not working means the sensor doesn´t appear? or the sensor appears but doesnt give values?

the sensor doesn´t appear, i just copy-paste

Ih8rain2 commented 2 years ago

You just did a copy-paste? And not working means the sensor doesn´t appear? or the sensor appears but doesnt give values?

the sensor doesn´t appear, i just copy-paste

Só there could a number of issues now. First do you use ewelink and does it exist there? Do you use other Sonoff items and do they appear? You have Sonoff Lan intergretion. Seems obvious..

If all are yes set debug to true in your config and find the entity in the initiation of the debug list first.

Perlnx commented 2 years ago

In the following function in cloud.py there is a mistake. Replace the existing 'def fix_attrs(deviceid: str, state: dict)' by this one and let me know if it worked for you: ""

try:

    # battery_level is common name for battery attribute
    if 'battery' in state:
        state[ATTR_BATTERY_LEVEL] = state['battery']

    for k in ('power', 'voltage', 'current'):
        if k in state:
            state[k] = float(state[k])

    # zigbee device
    if deviceid.startswith('a4'):
        for k in ('temperature', 'humidity'):
            if k in state:
                state[k] = int(state[k]) / 100.0        

    # "unavailable" in state creates a fault
    if state['currentHumidity'] == 'unavailable':
        _LOGGER.debug(f"TH humidity: unavailable")
    elif 'currentHumidity' in state:
        state['humidity'] = float(state['currentHumidity'])
        _LOGGER.debug(f"TH humidity: {state['humidity']}")
    if state['currentTemperature'] == 'unavailable':
        _LOGGER.debug(f"TH temperature: unavailable")
    elif 'currentTemperature' in state:
        state['temperature'] = float(state['currentTemperature'])
        _LOGGER.debug(f"TH temperature: {state['temperature']}")

except:
    pass

""

Good luck

Work great, Thank you !

AlexxIT commented 2 years ago

Fixed in latest master-version. Will be in next release. https://github.com/AlexxIT/SonoffLAN/releases

skaffff commented 1 year ago

I'm having some issues with getting all values from MS01 on THR316 in InfluxDB.

While ewelink app csv export shows all values each hour, I have only a few values imported in influxdb (like one every couple hours). CSV exports included for both ewelink, influx. Also diagnostics

ewelink_data.csv

influxDB Chronograf Data.csv

config_entry-sonoff-ee84b0b81fea4318e6fa8864da266746.json.txt

thanks