yangqian / hass-cozylife Goto Github PK
View Code? Open in Web Editor NEWthird party cozylife integration
License: MIT License
third party cozylife integration
License: MIT License
Adding the repo using HACS doesn't create the getconfig.py file anywhere. So I've tried manually creating it and filling it with the code listed here.
Running it from the config/homeassistant directory gave me best "results" with it still not finding the 'request' or 'utils" modules.
I know the last bulb IP address (all fixed IPs) and it tried manually entering the info of the IP and DID (pulled from the app) into my configuration.yaml without success. It reads "unavailable" on my dashboard.
Any ideas? I don't even have the alexa skill attached anymore.
Maybe reset the bulb?
light:
It was working fine before, but recently it is not working properly.
The current situation is: it can be used normally in HomeKit, but the official app and homeassistant cannot switch lights normally.
After deleting the cozylife configuration code in homeassistant, the official app can be used normally.
Is it their official limit?
Forgive my machine translation, because my English is too bad,thank you for your dedication
I am trying to change the entity name. Since this is setup in the config.yaml I can't do it from UI. But cannot use customize.yaml to change it either. Any suggestions?
potential future problem
Please can you update the function ? thank you
error i get when using your cozylife integration
Source: helpers/deprecation.py:205
TEMP_CELSIUS was used from hass_cozylife_local_pull, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfTemperature.CELSIUS instead, please report it to the author of the 'hass_cozylife_local_pull' custom integration
Hello, i ran the python script to scan my connected smart switch, but it shows that there's no connected cozylife devices
When I use the scene editor, I can add the entities, adjust the attributes of the color temp in Kelvin, save the scene but when I use the scene, it gives invalid values in the hs_color (HA error saying the value in hs_color needs to be within 360), the editor does not set the color_mode to color_temp or set the color_temp_Kelvin to any value. This is the section of the scene.yaml after using the editor to setup a two cozyLife lights:
I tried a manual setup of the scene with the following, the config is valid but the lights do not adjust when the scene is activated. I have reloaded the configs after each edit of the scene and also restart HA after edits but the light wont respond.
How can I use these lights in HA automation action?
I want to turn off all the lights when I leave home
I tried using Device option but cozylife discover only insert a entity rather than a device.
I tried using Service option but I only have these 2 services available:
is there a way to turn a light off by automation?
Thanks for your work. I hate these bulbs, only things that are fiddly af. Could you elaborate on the part about OTA? i saw port 5555 was open and i can build firmware, is there a password?
I can't get the switch entity to work, error below.
Error while setting up cozylife platform for switch
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/cozylife/switch.py", line 39, in setup_platform
_LOGGER.info(f'ip={hass.data[DOMAIN]}')
KeyError: 'cozylife'
It's working fine with application but I can add it to HA
I think the instructions are not sufficiently clear, or I miss somthing.
I follow these steps to set up the integration:
lights:
- platform: cozylife
lights:
- ip: 10.11.12.199
did: 671630877cb94cb41bcd
pid: d50v0i
dmn: Music Rhythm Light Strip
dpid: [1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14]
device_type: 01
switch:
- platform: cozylife
switches:
After this, I get next error:
Invalid config
The following integrations and platforms could not be set up:
lights (Show logs)
In the logs:
Logger: homeassistant.setup
Source: setup.py:221
First occurred: 19:03:06 (1 occurrences)
Last logged: 19:03:06
Setup failed for 'lights': Integration not found.
I've also tried to add:
hass-cozylife:
or
cozylife:
or
hass_cozylife_local_pull:
to configuration.yaml without success.
What am I missing?
Thanks!
Hello,
I'm very new to Raspi and I'm trying to setup some Cozylife smart plugs that I got recently to add to HA.
I've installed getConfig using "pip install getconfig' and then I navigate to the directory that it installs to: pi@raspberrypi:~/.local/lib/python3.9/site-packages/getConfig
I run the command "python3 getConfig.py 192.168.1.2 192.168.254.254" but nothing is returned, and no warnings or errors.
What am I doing wrong? I have the plugs detected and working in the Cozylife app.
I use the getconfig.py and got this:
$ python getconfig.py 192.xxx.xxx.1 192.xxx.xxx.253
IP scan from 192.xxx.xxx.1, end with 192.xxx.xxx.253
light:
- platform: cozylife
lights:
- ip: 192.xxx.xxx.118
did: 69333560acd82913d7cf
pid: p93sfg
dmn: Smart Bulb Light
dpid: [1, 2, 3, 4, 5, 7, 8, 9, 13, 14]
switch:
- platform: cozylife
switches:
copy into configuration.yaml and got this...
Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:230
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 4:11:36 AM (1 occurrences)
Last logged: 4:11:36 AM
[139961059280832] The system cannot restart because the configuration is not valid: Platform error switch.cozylife - Integration 'cozylife' not found. Platform error light.cozylife - Integration 'cozylife' not found.
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 986, in admin_handler
await result
File "/usr/src/homeassistant/homeassistant/components/homeassistant/__init__.py", line 191, in async_handle_core_service
raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: The system cannot restart because the configuration is not valid: Platform error switch.cozylife - Integration 'cozylife' not found.
Platform error light.cozylife - Integration 'cozylife' not found.
Tried to find an integration for cozylife but nothing in HASS
What am I missing?
I recently bought some cozylife temp sensors but I can't find a way to integrate them in HA
hello:
i have add the repository in hacs, and i run into my pc the config.py
light:
switch:
okey, i add into my config.yaml, i restart...but after? i don't show any entity ...where is it??? thank for u help
The switch I purchased last week cannot be added to Entities, but my lights can.
I changed to the official repository and they can all be added to Entities.
I restarted (homeassistant, switched the power on and off) many times and deleted the configuration in Apple home, leaving only the configuration in cozylife APP (because it needs to be connected to the Internet).
Is there anything else I need to provide so that I can help you?
light:
switch:
Everytime someone uses the actual physical switch it get lost in synchronization
Traceback (most recent call last):
File "/config/custom_components/cozylife/tcp_client.py", line 252, in _only_send
self._connect.send(self._get_package(cmd, payload))
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
return await service.entity_service_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call
response_data = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 591, in async_handle_light_off_service
await light.async_turn_off(**filter_turn_off_params(light, params))
File "/config/custom_components/cozylife/light.py", line 554, in async_turn_off
await super().async_turn_off(*kwargs)
File "/config/custom_components/cozylife/light.py", line 234, in async_turn_off
await self.hass.async_add_executor_job(self._tcp_client.control, {
File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/cozylife/tcp_client.py", line 268, in control
self._only_send(CMD_SET, payload)
File "/config/custom_components/cozylife/tcp_client.py", line 254, in _only_send
self._connect.send(self._get_package(cmd, payload))
BrokenPipeError: [Errno 32] Broken pipe
took me a whole day and some help of AI. But I finally made it to control a two gang switch with two seperate entities!
Split your configuration.yaml in two parts: "switches" for sockets etc. "switches2" for 2-gang wall switches
switch:
- platform: cozylife
switches:
- ip: 192.168.178.10
did: 51039349083a8d53f900 #Sekretär
pid: esEM1c
dmn: Metering Socket
dpid: [1, 2, 3, 18, 19, 20, 21, 26, 27, 28, 29, 30, 31, 32]
switches2:
- ip: 192.168.178.12
did: 4324820980646f4c6700 #Wohnzimmer
pid: e5aHVS
dmn: Smart switch
dpid: [1, 2, 3, 4, 5]
replace your custom_components/cozylife/switch.py with this:
"""Platform for sensor integration."""
from __future__ import annotations
import logging
from .tcp_client import tcp_client
from datetime import timedelta
import asyncio
from homeassistant.components.sensor import SensorEntity
from homeassistant.components.switch import SwitchEntity
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.event import async_track_time_interval
from typing import Any, Final, Literal, TypedDict, final
from .const import (
DOMAIN,
SWITCH_TYPE_CODE,
LIGHT_TYPE_CODE,
LIGHT_DPID,
SWITCH,
WORK_MODE,
TEMP,
BRIGHT,
HUE,
SAT,
)
SCAN_INTERVAL = timedelta(seconds=20)
_LOGGER = logging.getLogger(__name__)
_LOGGER.info(__name__)
SCAN_INTERVAL = timedelta(seconds=1)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_devices: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None
) -> None:
"""Set up the sensor platform."""
# We only want this platform to be set up via discovery.
# logging.info('setup_platform', hass, config, add_entities, discovery_info)
_LOGGER.info('setup_platform')
#_LOGGER.info(f'ip={hass.data[DOMAIN]}')
#if discovery_info is None:
# return
switches = []
for item in config.get('switches') or []:
client = tcp_client(item.get('ip'))
client._device_id = item.get('did')
client._pid = item.get('pid')
client._dpid = item.get('dpid')
client._device_model_name = item.get('dmn')
switches.append(CozyLifeSwitch(client, hass, 'wippe1'))
for item in config.get('switches2') or []:
client = tcp_client(item.get('ip'))
client._device_id = item.get('did')
client._pid = item.get('pid')
client._dpid = item.get('dpid')
client._device_model_name = item.get('dmn')
# Create two entities for each switch, one for each rocker
switches.append(CozyLifeSwitch(client, hass, 'wippe1'))
switches.append(CozyLifeSwitch(client, hass, 'wippe2'))
async_add_devices(switches)
for switch in switches:
await hass.async_add_executor_job(switch._tcp_client._initSocket)
await asyncio.sleep(0.01)
async def async_update(now=None):
for switch in switches:
await hass.async_add_executor_job(switch._refresh_state)
await asyncio.sleep(0.01)
async_track_time_interval(hass, async_update, SCAN_INTERVAL)
class CozyLifeSwitch(SwitchEntity):
_tcp_client = None
_attr_is_on = True
_wippe = None # Add a new attribute to track the rocker
def __init__(self, tcp_client: tcp_client, hass, wippe: str) -> None:
"""Initialize the sensor."""
_LOGGER.info('__init__')
self.hass = hass
self._tcp_client = tcp_client
self._unique_id = tcp_client.device_id + '_' + wippe
self._name = tcp_client.device_id[-4:] + ' ' + wippe
self._wippe = wippe # Set the rocker attribute
self._refresh_state()
@property
def unique_id(self) -> str | None:
"""Return a unique ID."""
return self._unique_id
async def async_update(self):
await self.hass.async_add_executor_job(self._refresh_state)
def _refresh_state(self):
self._state = self._tcp_client.query()
_LOGGER.info(f'_name={self._name},_state={self._state}')
if self._state:
if self._wippe == 'wippe1':
self._attr_is_on = (self._state['1'] & 0x01) == 0x01
elif self._wippe == 'wippe2':
self._attr_is_on = (self._state['1'] & 0x02) == 0x02
@property
def name(self) -> str:
return 'cozylife:' + self._name
@property
def available(self) -> bool:
"""Return if the device is available."""
if self._tcp_client._connect:
return True
else:
return False
@property
def is_on(self) -> bool:
"""Return True if entity is on."""
return self._attr_is_on
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""
self._attr_is_on = True
_LOGGER.info(f'turn_on:{kwargs}')
if self._wippe == 'wippe1':
await self.hass.async_add_executor_job(self._tcp_client.control, {
'1': self._state['1'] | 0x01
})
elif self._wippe == 'wippe2':
await self.hass.async_add_executor_job(self._tcp_client.control, {
'1': self._state['1'] | 0x02
})
return None
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
self._attr_is_on = False
_LOGGER.info('turn_off')
if self._wippe == 'wippe1':
await self.hass.async_add_executor_job(self._tcp_client.control, {
'1': self._state['1'] & ~0x01
})
elif self._wippe == 'wippe2':
await self.hass.async_add_executor_job(self._tcp_client.control, {
'1': self._state['1'] & ~0x02
})
return None
adjust SCAN_INTERVAL = timedelta(seconds=1) (in my case 1 second) to improve status response speed of the switch. Going below 1 sec. could maybe decrease your homeassistant's performance.
"wippe" stands for rocker
I found information about how to control certain rockers here:
https://github.com/cozylife/dpid_document/blob/main/electrician_zh.md
Hello, I really appreciate your work. I improved 2-3 things to make the rendering code clearer.
In addition I corrected the switches and it works perfectly for me.
However, I would like help because I can't find it, because I have a connected socket with consumption monitoring and I would like to recover this consumption.
Do you have an idea ?
Sincerely
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.