-
Notifications
You must be signed in to change notification settings - Fork 449
Description
Hi @AlexxIT,
Thank you for the amazing SonoffLAN integration!
I'm using Sonoff THR316D device (UIID 181) and found that its firmware exposes an autoControlEnabled parameter in params. This parameter represents the device’s Auto Mode state, but SonoffLAN does not currently expose it as an entity.
The code provided exposes the autoControlEnabled parameter as a separate entity. I implemented support locally and confirmed:
- Auto‑Mode toggle works flawlessly
- Only UIID 181 devices receive the new entity
- No other models should be affected
The changes in code are minimal and should be made in two files:
- in switch.py in custom-components/sonoff folder
- and init.py in custom-components/sonoff/core/ewelink folder
[not the other init.py in root folder]
✅ 1. Changes to switch.py
This adds a new switch entity class: XAutoModeSwitch.
➤ Insert after the end of XSwitchTH class
It follows SonoffLAN’s existing patterns and properly maps boolean values to HA’s switch model.
# --- BEGIN NEW Auto Mode Switch (for THR316D/THR320D) ---
# XAutoModeSwitch: exposes 'autoControlEnabled' as a HA switch entity
class XAutoModeSwitch(XEntity, SwitchEntity):
param = "autoControlEnabled"
def __init__(self, ewelink: XRegistry, device: dict):
super().__init__(ewelink, device)
self._attr_has_entity_name = True
self._attr_name = "Auto Mode"
self._is_on = False
def set_state(self, params: dict):
val = params.get(self.param)
if isinstance(val, str):
self._is_on = val in ("1", "true", "on", "True", "ON")
else:
self._is_on = bool(val)
@property
def is_on(self) -> bool:
return bool(self._is_on)
async def async_turn_on(self, **kwargs):
await self.ewelink.send(self.device, {self.param: 1})
async def async_turn_off(self, **kwargs):
await self.ewelink.send(self.device, {self.param: 0})
# --- END NEW Auto Mode Switch ---
✅ 2. Changes to 'init.py'
NOTE: make change to 'init.py' in custom-integrations/sonoff/core/ewelink folder
[not the other init.py in root folder]
These lines create a separate entity 'autoControlEnabled' only for THR316D/THR320D, which are UIID 181.
This avoids exposing incorrect switches on other devices.
➤ Insert inside setup_devices() directly after:
entities += [cls(self, device) for cls in get_spec(device)]
# --- BEGIN NEW Auto Mode support for UIID 181 (THR316D/THR320D) ---
from ...switch import XAutoModeSwitch
# Only these thermostats expose 'autoControlEnabled' meaningfully
if device.get("extra", {}).get("uiid") == 181:
if "autoControlEnabled" in device.get("params", {}):
entities.append(XAutoModeSwitch(self, device))
# --- END NEW Auto Mode support --- #
✔ Why this change is safe
UIID 181 corresponds specifically to THR316D / THR320D.
The integration checks both UIID and the presence of the parameter, ensuring no unrelated device gets the entity.
Code aligns with the structure and patterns in SonoffLAN’s existing entity classes.
Request
Could you consider including these additions in a future release of SonoffLAN?
Also, other's that have THR316D device, feel free to test the code and report if it works.
Thanks again for your fantastic work!