Coder Social home page Coder Social logo

torrottum / ikea-ansluta-esphome Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 3.0 81 KB

IKEA Ansluta integration for Home Assistant using ESPHome with a D1 Mini and CC2500.

C++ 89.17% Python 10.83%
esphome homeassistant ikea ikea-ansluta ikea-omlopp ikea-utrusta

ikea-ansluta-esphome's People

Contributors

torrottum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ikea-ansluta-esphome's Issues

Mqtt branch!

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.

Great stuff!

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
???

Component not found: ikea_ansluta.

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 custom light component

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.

Clean up code, adhere to esphome standards

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

Pair directly with the lights and intercept commands from the remote

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%.

Documentation improvement

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/

Use external component mechanism

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 :)

No 50% brightness through the original remote

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.

Build fails

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 ==========================

Implement remote as sensor

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

Support 50% brightness

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.

Doesn't work with Esphome 2021.8.0

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

Running on ESP32 causes lockup after "WiFi Scan Done"

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?

Watchdog triggers after adding a light

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...

Improve remote sniffing and command sending

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

Refactor into "real" custom component

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.

Todo

  • Refactor radio
    • Config schema
    • Needs to be SPIDevice
    • Use uint8_t instead of char
    • Use uint16_t instead of short
    • Need to switch from Arduino methods
    • A way to register callbacks
    • Debounce remote presses
  • Refactor ansluta_light
    • Config schema
    • Register callback
    • Handle callback
  • Clean up code
  • Write upgrade guide
  • Move yaml to example folder

Pairing without remote

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

Create actions

  • ikea_ansluta.enable_pairing_mode
  • ikea_ansluta.disable_pairing_mode
  • ikea_ansluta.send_command

Multi devices

Hey
Can you please make an example when you have multi ansluta/utrusta.
I have 2 different units with 2 different remotes.

ESPHome component for CC2500 radio module

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?

Create linting scripts

I think it will be nice to follow esphome's code style.
Create linting scripts for running:

  • Python
    • flake8
    • pylint
  • C++
    • clang-tidy
    • clang-format

Improve documentation

  • How to set up/pair
  • Document ikea_ansluta component
    • Options
      • send_command_times
      • sniff_after_command_sent_x_times
    • Triggers
      • on_remote_click
    • Actions
      • ikea_ansluta.enable_pairing_mode and ikea_ansluta.disable_pairing_mode
  • Document light component
    • Options
      • address
      • pairing_mode
      • threshold
    • Triggers
      • on_change
  • Examples
    • How to retain original functionality of the remote when paired directly (50%, 100%, 50%, OFF sequence)
    • Exposing the remote to HA through a template sensor or event

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.