torrottum / ikea-ansluta-esphome Goto Github PK
View Code? Open in Web Editor NEWIKEA Ansluta integration for Home Assistant using ESPHome with a D1 Mini and CC2500.
IKEA Ansluta integration for Home Assistant using ESPHome with a D1 Mini and CC2500.
Hey,
Can you please make a MQTT branch that has the dimmer funktion?
Mqtt is universal and lets you use alot of other program then homeassistant.
There alot of benefits to keep mqtt .
Thank you in advance.
I was just failing creating my own custom component with the same codebase.
A question:
Can you explain how I setup if I already know the AddressByteA and AddressByteB?
Is it as simple as
(0xb8 << 4) + 0x66
==
3046
where
0xb8 = A and
0x66 = B
???
I've the following error when compiling ESPHome project
INFO Reading configuration /config/esphome/olmop01.yaml...
Failed config
ikea_ansluta: [source /config/esphome/olmop01.yaml:33]
Component not found: ikea_ansluta.
cs_pin: GPIO15
done: I put the file folder in Hass.io under /root/config/esphome/custom_components/ikea_ansluta
Switch to using a custom light component instead of a MQTT component.
I think that will simplify things a bit and we don't need to rely on MQTT topics for state, brightness, etc. Also we get auto discovery and availability. Only downside is that it will only work for one remote, but I only have one anyways.
The easiest way to do it is to just use the esphome source code and bind mount custom_components/ikea_ansluta
into esphome/esphome/components
and use the esphome-lint docker container and scripts.
Will create linting scripts later
Turning on the lights using Home Assistant is actually a bit more reliable than using the IKEA remote (sometimes not all lights turn on/off). I think this is because this send the commands 200 times while the remote sends them 50 times.
Another issue is that the remote keeps its own state. If the lights are off and I click the remote 3 times the lights will go 50%, 100%, 50%. If I then turn off the lights with HA I need to press the remote 2 times to turn the lights on again. Because the remote sends off and then 50%.
Home Assistant uses a general custom_components
directory for non-standard plugins for HA itself. This code, however, should be installed in a directory specific to ESPHome, with the same name but under the esphome
directory. Experienced ESPHome users may know this, but for someone new to both Home Assistant and ESPHome it's not obvious that ESPHome needs its own directory. IMHO the documentation would benefit from stating this explicitly.
E.g.:
[core-ssh ~]$ ls -1d config/custom_components/ config/esphome/custom_components/
config/custom_components/
config/esphome/custom_components/
ESPHome v1.18.0 added support for external components, which are an easier way to use custom components. It'd be great if you could rename the custom_components
folder to components
, so that your component can also be used in this way :)
Hey. I have updated ikea-ansluta-esphome to 1.1.0 and repaired my lights to communicate directly with cc2500.
Now i can set brightness to 50% through my HA but lost ability to do that with the original remote.
I've followed the install instructions, but the build fails with this. It's using the arduino framework, but somehow digitalWrite and HIGH are undefined?
INFO ESPHome 2023.10.3
INFO Reading configuration /config/ansluta.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing ansluta (board: m5stack-atom; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
- toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- noise-c @ 0.1.4
|-- SPI @ 2.0.0
Compiling .pioenvs/ansluta/src/esphome/components/ikea_ansluta/ikea_ansluta.cpp.o
Compiling .pioenvs/ansluta/src/esphome/components/md5/md5.cpp.o
Compiling .pioenvs/ansluta/src/esphome/components/mdns/mdns_component.cpp.o
Compiling .pioenvs/ansluta/src/esphome/components/mdns/mdns_esp32.cpp.o
src/esphome/components/ikea_ansluta/ikea_ansluta.cpp: In member function 'void esphome::ikea_ansluta::IkeaAnsluta::send_command(uint16_t, esphome::ikea_ansluta::IkeaAnslutaCommand)':
src/esphome/components/ikea_ansluta/ikea_ansluta.cpp:180:26: error: 'HIGH' was not declared in this scope
digitalWrite(SS, HIGH);
^~~~
src/esphome/components/ikea_ansluta/ikea_ansluta.cpp:180:9: error: 'digitalWrite' was not declared in this scope
digitalWrite(SS, HIGH);
^~~~~~~~~~~~
src/esphome/components/ikea_ansluta/ikea_ansluta.cpp:180:9: note: suggested alternative: 'spiWrite'
digitalWrite(SS, HIGH);
^~~~~~~~~~~~
spiWrite
Compiling .pioenvs/ansluta/src/esphome/components/mdns/mdns_esp8266.cpp.o
*** [.pioenvs/ansluta/src/esphome/components/ikea_ansluta/ikea_ansluta.cpp.o] Error 1
========================== [FAILED] Took 1.96 seconds ==========================
I think a better solution to #2 could be to implement the remote as a sensor. Then it's possible to set up the automation in HA or the esphome config. I think that will be easier to create sequences for the dimming
I think the best way would be to just implement normal brightness support and set the light to 50% and 100% based on different thresholds.
Another option could be to have a switch for each level.
src/esphome/components/ikea_ansluta/light/light.cpp: In member function 'virtual esphome::light::LightTraits esphome::ikea_ansluta::Light::get_traits()':
src/esphome/components/ikea_ansluta/light/light.cpp:28:10: error: 'class esphome::light::LightTraits' has no member named 'set_supports_brightness'
traits.set_supports_brightness(true);
^
*** [/data/kitchen_counter/.pioenvs/kitchen_counter/src/esphome/components/ikea_ansluta/light/light.cpp.o] Error 1
Need to change to the new color modes.
In both v1 and v2
Hi,
Thanks for the project. I'm trying to run this on an ESP32, it seems to compile and upload successfully, but when it runs, it reaches "Starting scan..." then hangs after "Event: WiFi Scan Done". Does this project not support ESP32?
When adding a light to the config, the watchdog starts triggering.
This is the config without light:
esphome:
name: ansluta
friendly_name: Ansluta
esp32:
board: m5stack-atom
framework:
type: arduino
logger:
level: VERBOSE
api:
encryption:
key: "xxx"
ota:
password: "yyy"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
spi:
clk_pin: GPIO23
mosi_pin: GPIO19
miso_pin: GPIO33
ikea_ansluta:
cs_pin: GPIO22
This config works fine:
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4
[ 6][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
[I][logger:326]: Log initialized
[C][ota:473]: There have been 2 suspected unsuccessful boot attempts.
[D][esp32.preferences:114]: Saving 1 preferences to flash...
[V][esp32.preferences:126]: sync: key: 233825507, len: 4
[D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[V][app:030]: Sorting components by setup priority...
[D][spi:039]: Setting up SPI bus...
[D][spi_device:355]: mode 0, data_rate 4000kHz
[C][wifi:038]: Setting up WiFi...
[C][wifi:051]: Starting WiFi...
[C][wifi:052]: Local MAC: xyz
[V][esp32.preferences:059]: nvs_get_blob('1269076133'): ESP_ERR_NVS_NOT_FOUND - the key might not be set yet
[V][wifi_esp32:039]: Enabling STA.
[ 109][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[V][wifi_esp32:417]: Event: WiFi ready
[ 200][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[ 201][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
[V][wifi_esp32:428]: Event: WiFi STA start
[ 6326][V][WiFiGeneric.cpp:381] _arduino_event_cb(): SCAN Done: ID: 128, Status: 0, Results: 10
[ 6327][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 1 - SCAN_DONE
[V][wifi_esp32:422]: Event: WiFi Scan Done status=0 number=10 scan_id=128
[D][wifi:443]: Found networks:
[I][wifi:487]: - 'IoT' [redacted]▂▄▆█
[D][wifi:488]: Channel: 7
[D][wifi:489]: RSSI: -51 dB
[I][wifi:277]: WiFi Connecting to 'IoT'...
[V][wifi:279]: Connection Params:
[V][wifi:280]: SSID: 'IoT'
[V][wifi:283]: BSSID: xyz
[V][wifi:303]: Password: [redacted]
[V][wifi:308]: Channel: 7
[V][wifi:317]: Using DHCP IP
[V][wifi:319]: Hidden: NO
[ 7147][V][WiFiGeneric.cpp:353] _arduino_event_cb(): STA Connected: SSID: IoT, BSSID: xyz, Channel: 7, Auth: WPA2_PSK
[ 7148][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 4 - STA_CONNECTED
[V][wifi_esp32:442]: Event: Connected ssid='IoT' bssid=[redacted] channel=7, authmode=WPA2 PSK[ 7171][V][WiFiGeneric.cpp:367] _arduino_event_cb(): STA Got New IP:10.x.x.x
[ 7177][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 7 - STA_GOT_IP
[ 7181][D][WiFiGeneric.cpp:991] _eventCallback(): STA IP: 10.x.x.x, MASK: 255.255.0.0, GW: 10.x.x.x
[V][wifi_esp32:496]: Event: Got IP static_ip=10.x.x.x gateway=10.x.x.x
[C][ota:097]: Over-The-Air Updates:
[C][ota:098]: Address: ansluta.local:3232
[C][ota:101]: Using Password.
[W][ota:107]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts
[C][api:025]: Setting up Home Assistant API server...
[I][app:062]: setup() finished successfully!
[I][app:102]: ESPHome version 2023.10.3 compiled on Oct 27 2023, 17:21:09
[C][wifi:546]: WiFi:
[C][wifi:382]: Local MAC: xyz
[C][wifi:383]: SSID: [redacted]
[C][wifi:384]: IP Address: 10.x.x.x
[C][wifi:386]: BSSID: [redacted]
[C][wifi:387]: Hostname: 'ansluta'
[C][wifi:389]: Signal strength: -51 dB ▂▄▆█
[V][wifi:391]: Priority: 0.0
[C][wifi:393]: Channel: 7
[C][wifi:394]: Subnet: 255.255.0.0
[C][wifi:395]: Gateway: 10.x.x.x
[C][wifi:396]: DNS1: 10.x.x.x
[C][wifi:397]: DNS2: 0.0.0.0
[C][logger:416]: Logger:
[C][logger:417]: Level: VERBOSE
[C][logger:418]: Log Baud Rate: 115200
[C][logger:420]: Hardware UART: UART0
[C][spi:067]: SPI bus:
[C][spi:068]: CLK Pin: GPIO23
[C][spi:069]: SDI Pin: GPIO33
[C][spi:070]: SDO Pin: GPIO19
[C][spi:072]: Using HW SPI: SPI
[C][ikea_ansluta:063]: CS Pin: GPIO22
[C][mdns:115]: mDNS:
[C][mdns:116]: Hostname: ansluta
[V][mdns:117]: Services:
[V][mdns:119]: - _esphomelib, _tcp, 6053
[V][mdns:121]: TXT: friendly_name = Ansluta
[V][mdns:121]: TXT: version = 2023.10.3
[V][mdns:121]: TXT: mac = xyz
[V][mdns:121]: TXT: platform = ESP32
[V][mdns:121]: TXT: board = m5stack-atom
[V][mdns:121]: TXT: network = wifi
[V][mdns:121]: TXT: api_encryption = Noise_NNpsk0_25519_ChaChaPoly_SHA256
[C][ota:097]: Over-The-Air Updates:
[C][ota:098]: Address: ansluta.local:3232
[C][ota:101]: Using Password.
[W][ota:107]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts
[C][api:138]: API Server:
[C][api:139]: Address: ansluta.local:6053
[C][api:141]: Using noise encryption: YES
But if I add a light:
light:
- platform: ikea_ansluta
name: 'Benkelys'
remote_address: 0x35c0
The device fails to boot:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4
[ 6][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
[I][logger:326]: Log initialized
[C][ota:473]: There have been 5 suspected unsuccessful boot attempts.
[D][esp32.preferences:114]: Saving 1 preferences to flash...
[V][esp32.preferences:126]: sync: key: 233825507, len: 4
[D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[V][app:030]: Sorting components by setup priority...
[D][spi:039]: Setting up SPI bus...
[C][light:035]: Setting up light 'Benkelys'...
[D][light:036]: 'Benkelys' Setting:
[D][light:041]: Color mode:
[D][spi_device:355]: mode 0, data_rate 4000kHz
[C][wifi:038]: Setting up WiFi...
[C][wifi:051]: Starting WiFi...
[C][wifi:052]: Local MAC: xyz
[V][esp32.preferences:059]: nvs_get_blob('3278020994'): ESP_ERR_NVS_NOT_FOUND - the key might not be set yet
[V][wifi_esp32:039]: Enabling STA.
[ 131][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[V][wifi_esp32:417]: Event: WiFi ready
[ 225][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[ 226][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
[V][wifi_esp32:428]: Event: WiFi STA start
E (10802) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (10802) task_wdt: - loopTask (CPU 1)
E (10802) task_wdt: Tasks currently running:
E (10802) task_wdt: CPU 0: IDLE
E (10802) task_wdt: CPU 1: IDLE
E (10802) task_wdt: Aborting.
abort() was called at PC 0x400f3b00 on core 0
Backtrace:0x400837b9:0x3ffbeafc |<-CORRUPTED
ELF file SHA256: 0000000000000000
Rebooting...
Currently the sniffing of the remote is a bit unreliable/slow since it has to wait for the command sending for loop to finish.
I think one possible solution can be to move the command sending to the component loop and try to sniff the remote(s) before sending a command or in between every n commands sent
I think it's better to create a real/proper custom component for esphome.
I haven't figured out all the details yet, but currently I'm thinking the configuration should be something like this (to support the features currently in the develop branch as of commit bf87676):
# Other esphome stuff
spi:
clk_pin: GPIO14
miso_pin: GPIO12
mosi_pin: GPIO13
ikea_ansluta:
cs_pin: GPIO15
# Two remotes
light:
- platform: ikea_ansluta
name: "IKEA Ansluta 1"
remote_address: '0x35c0'
- platform: ikea_ansluta
name: "IKEA Ansluta 2"
remote_address: '0x35c1'
I've looked a bit into how the Tuya components in 1.15.0 works and I think it should be doable.
What I'm not sure about yet is how to solve #2, but I think doing this way will add more flexibility for solving that problem.
Hi,
Can I pair an ansluta power supply without a remote control?
I added to the config file: pairing_enabled: true How can I initiate the pairing process?
Could it be that the wiring is wrong? How can I ensure that the hardware is ok?
In the log I could not find any error message. Also if I run the ESP without connected CC2500.
Any advice would be very much appreciated
Thank you
Peter
Can you please add HACS support?
ikea_ansluta.enable_pairing_mode
ikea_ansluta.disable_pairing_mode
ikea_ansluta.send_command
Hey
Can you please make an example when you have multi ansluta/utrusta.
I have 2 different units with 2 different remotes.
Hi! First I'd like to give a shout out for creating this ESPHome component, good work!
I'm developing an ESPHome component for the Philips LivingColors gen 1 which also uses the CC2500 radio module, and your component is very helpful for understanding what I need to do and I'm lending parts of your code to make my life easier. I hope you don't mind.
And I'm actually making a separate component for the CC2500 which can then be used for my own integration aswel as for other users to be used. I have that working, but to make it a generic component I now need to decide which registers should be configurable.
Comparing your CC2500 code with a reference implementation for my Philips LivingColors gen 1 I see differences by which values are written to which register. So far I found, by trail and error, most registers not making much of a difference for atleast my LivingColors light.
Using the CC2500 datasheet I have identified the following registers which make a difference:
ADDR - Device address, actually values 0x00 and 0xFF are both broadcast addresses
CHANNR - Channel number
FSCTRL1 and FSCTRL2 - define the frequency
FREQ2, FREQ1, FREQ0 - also something to do with frequency
MDMCFG4 - MDMCFG0 - modem configuration, including modulation format and encoding
PATABLE - output power
How did you decide which values need to be written to each register?
I think it will be nice to follow esphome's code style.
Create linting scripts for running:
send_command_times
sniff_after_command_sent_x_times
on_remote_click
ikea_ansluta.enable_pairing_mode
and ikea_ansluta.disable_pairing_mode
address
pairing_mode
threshold
on_change
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.