Skip to content

Multiple fixes, new device support, and dynamic device discovery#186

Open
nrbrt wants to merge 29 commits intosanjoyg:mainfrom
nrbrt:main
Open

Multiple fixes, new device support, and dynamic device discovery#186
nrbrt wants to merge 29 commits intosanjoyg:mainfrom
nrbrt:main

Conversation

@nrbrt
Copy link

@nrbrt nrbrt commented Jan 25, 2026

This PR combines several fixes and improvements:

New Features

Dynamic Device Discovery (Issue #139)

Devices added or removed from the Dirigera hub are now automatically reflected in Home Assistant without requiring a restart.

  • DeviceDiscoveryCoordinator handles runtime entity registration
  • deviceAdded WebSocket events trigger discovery for new devices
  • deviceRemoved events mark entities as unavailable (safe, no auto-delete)
  • Name changes in IKEA app sync to HA entity names
  • Room/area changes sync to HA device registry areas

Tested scenarios:

  • Add device from scratch: entity appears in correct room with icon
  • Remove device: entity becomes unavailable
  • Rename device in IKEA app: HA entity name updates
  • Move device to different room: HA device area updates

New Device Support

MYGGSPRAY Motion Sensors (E2494)

  • Add occupancySensor device type support (IKEA reports these as occupancySensor, not motionSensor)
  • Add to WebSocket event listener for real-time updates

RODRET/STYRBAR Remote Controls (lightController)

  • Add remotePressEvent handling for lightController device types
  • These remotes fire events differently than shortcutController types
  • Add STYRBAR (E2002) to CONTROLLER_BUTTON_MAP with 4 buttons
  • Add button 3/4 translations for STYRBAR

ALPSTUGA Air Quality Sensor

  • Add CO2 sensor support (current_c_o2 attribute)

Bug Fixes

Light Color Mode Not Updating (NEW)

  • colorHue and colorSaturation were missing from the WebSocket event whitelist, so color changes made in the IKEA Home app were silently ignored by HA
  • color_mode was set once at initialization and never updated, so switching between HS color and color temperature on RGBWW lamps was not reflected in HA
  • Now dynamically updates color_mode (HS ↔ COLOR_TEMP) when color attributes change, both from external changes (IKEA app) and HA-initiated changes
  • Also fixes a typo in the color_hue setter (self.json_dataself._json_data)

Device Reachability Not Updating (#147)

  • Fix: schedule_update_ha_state() was only called when attribute changes were received
  • If a device only sent isReachable change (no other attributes), HA was never notified
  • Now tracks reachability changes separately and updates HA state accordingly
  • Devices now correctly show as "unavailable" when they go offline

Device Trigger Prefix Mismatch (Important!)

  • Fix inconsistency between device_trigger.py and hub_event_listener.py
  • hub_event_listener uses regex to detect _X suffix in device ID and adds buttonX_ prefix
  • device_trigger only checked number_of_buttons > 1, causing triggers to not match events
  • Now both use the same logic, fixing automations for RODRET and similar controllers

Color Temperature Unit Conversion

  • Fix mired/Kelvin conversion in ikea_bulb_device
  • HA expects color_temp in mireds, was incorrectly providing Kelvin

Environment Sensor State Class

  • Add state_class: measurement to temperature, humidity, PM2.5, VOC, CO2 sensors
  • Enables Long Term Statistics in Home Assistant

Deprecation Warning

  • Replace deprecated OptionsFlow with OptionsFlowWithConfigEntry
  • Fixes warning on HA 2024.12+

Testing

Tested on Home Assistant 2026.1+ with:

  • MYGGSPRAY motion sensors (E2494)
  • RODRET Dimmer (E2201)
  • ALPSTUGA air quality sensor
  • TRÅDFRI bulbs and RGBWW lamps (color + color temperature switching)
  • Device offline detection (isReachable)
  • Dynamic device add/remove/rename/room change

Closes #139, #147

nrbrt and others added 9 commits January 13, 2026 11:33
IKEA MYGGSPRAY motion sensors (E2494) report as deviceType
'occupancySensor' instead of 'motionSensor'. They also lack the
'is_on' attribute that regular motion sensors have.

This PR fixes both issues by:
- Including 'occupancySensor' in motion sensor queries
- Creating MotionSensorX with optional is_on attribute
- Overriding get_motion_sensors() and get_motion_sensor_by_id()

Tested with IKEA MYGGSPRAY E2494 sensors on Home Assistant 2026.1.1.
MYGGSPRAY motion sensors send events as occupancySensor device type.
Without this, the hub_event_listener ignores real-time state changes
from these sensors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
STYRBAR has 4 buttons but was treated as 1-button controller.
This enables button1_*, button2_*, button3_*, button4_* triggers.
Adds English translations for button3_* and button4_* triggers
to support 4-button controllers like STYRBAR.
STYRBAR, RODRET and similar lightController-type remotes send
remotePressEvent messages via WebSocket instead of sceneUpdated.
Previously these were discarded as "non state message".

This commit adds a new handler (parse_remote_press_event) that:
- Parses remotePressEvent messages from lightController devices
- Converts clickPattern to trigger types (single_click, long_press, etc)
- Handles multi-button controllers using the _N suffix
- Debounces duplicate events within 1 second (IKEA bug workaround)
- Fires dirigera_platform_event for Home Assistant automations

Enables use of STYRBAR 4-button and RODRET 2-button remotes in
Home Assistant automations without requiring scene configuration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
nrbrt and others added 2 commits January 25, 2026 12:04
The min_color_temp_kelvin, max_color_temp_kelvin, and color_temp_kelvin
properties were returning raw mired values from Dirigera instead of
converting them to Kelvin as Home Assistant expects.

Also fixed async_turn_on to use direct API patch for setting color
temperature, bypassing the dirigera library's broken validation that
rejects valid Kelvin values.

Fixes sanjoyg#181

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Changed OptionsFlowHandler to inherit from OptionsFlowWithConfigEntry
instead of OptionsFlow with explicit self.config_entry assignment.

This fixes the deprecation warning:
"Detected that custom integration 'dirigera_platform' sets option flow
config_entry explicitly, which is deprecated"

Fixes sanjoyg#170

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The IKEA ALPSTUGA air quality monitor reports CO2 levels via the
currentCO2 attribute, but the dirigera library doesn't have this
field in its EnvironmentSensorAttributes pydantic model yet.

This commit:
- Creates patched EnvironmentSensorAttributesX with current_c_o2 field
- Creates EnvironmentSensorX class using the patched attributes
- Adds get_environment_sensors/get_environment_sensor_by_id to HubX
- Updates add_environment_sensors to create CO2 entities
- Adds None default to getattr calls for safer attribute checking

Fixes sanjoyg#178

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
device_trigger.py now uses the same regex pattern as hub_event_listener.py
to determine whether to add the buttonX_ prefix to trigger types.

Previously, device_trigger only checked number_of_buttons > 1, but
hub_event_listener checks if the device ID ends with _X suffix (e.g. "xxx_1")
and always adds the prefix in that case. This caused a mismatch where:
- Events fired as "button1_single_click"
- Triggers registered as "single_click"

This affected RODRET and similar controllers where the device ID has a _1
suffix but number_of_buttons is 1.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
nrbrt and others added 3 commits January 26, 2026 05:54
The previous fix incorrectly assumed the Dirigera API returned color
temperature values in mired (micro reciprocal degrees) and converted
them to Kelvin. However, the API already returns Kelvin values directly:

- colorTemperature: current temp in Kelvin (e.g. 6535)
- colorTemperatureMin: coldest/highest Kelvin (e.g. 4000)
- colorTemperatureMax: warmest/lowest Kelvin (e.g. 2202)

The erroneous conversion (1000000/value) resulted in values like 250K
and 454K, which are way below the visible light spectrum and caused
the UI to display incorrect colors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
These environment sensors were missing state_class="measurement",
which caused Home Assistant to show warnings about missing state_class
for Long Term Statistics.

Sensors fixed:
- ikea_vindstyrka_humidity
- ikea_vindstyrka_pm25 (current, min, max)
- ikea_vindstyrka_voc_index
- ikea_alpstuga_co2

Temperature already had state_class set.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Previously, schedule_update_ha_state() was only called when attribute
changes were received via WebSocket. If a device only sent an
isReachable change (without other attributes), the internal value was
updated but Home Assistant was never notified.

This caused devices to appear as "available" in HA even after they
went offline in the Dirigera hub.

The fix tracks reachability changes separately and ensures
schedule_update_ha_state() is called when either attributes OR
reachability changes.

Fixes sanjoyg#147

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Devices added or removed from the Dirigera hub are now automatically
reflected in Home Assistant without requiring a restart.

Features:
- DeviceDiscoveryCoordinator handles runtime entity registration
- WebSocket events trigger discovery for new devices (deviceAdded)
- Removed devices become unavailable (deviceRemoved)
- Name changes sync from IKEA app to HA entity names
- Room/area changes sync to HA device registry areas
- Outlet entities show proper icon via device_class

Implementation:
- New device_discovery.py with DeviceDiscoveryCoordinator class
- Modified hub_event_listener.py to handle deviceAdded/deviceRemoved
- Updated all platforms (light, switch, sensor, etc.) to register
  with the discovery coordinator
- Entity names update dynamically from device custom_name attribute

Tested scenarios:
- Add device from scratch: entity appears in correct room with icon
- Remove device: entity becomes unavailable (safe, no auto-delete)
- Rename device in IKEA app: HA entity name updates
- Move device to different room: HA device area updates

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nrbrt nrbrt changed the title Multiple fixes and new device support Multiple fixes, new device support, and dynamic device discovery Jan 26, 2026
nrbrt and others added 9 commits January 27, 2026 08:56
When a lamp color was changed via the IKEA Home app, Home Assistant
did not reflect the change because:

1. colorHue and colorSaturation were missing from the WebSocket event
   whitelist, so color changes were silently ignored
2. color_mode was set once at initialization and never updated, so
   switching between HS color and color temperature (e.g. on RGBWW
   lamps) was not reflected in HA

Changes:
- Add colorHue and colorSaturation to light event processing list
- Dynamically update color_mode in event listener when color
  attributes change (HS vs COLOR_TEMP)
- Update color_mode in async_turn_on for HA-initiated changes
- Fix color_hue setter typo (self.json_data → self._json_data)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Updated README to include additional information about the integration and donation details.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace external link to sanjoyg wiki with docs/dump-data.md.
Also update screenshot paths to use relative links.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added recommendation to revert to upstream if it becomes active again and noted plans for answering questions and filing PRs.
Corrected spelling of 'recommend' in README.
Some bulbs (e.g. KAJPLATS) only send colorMode in the
deviceStateChanged event after a scene activation, without the actual
color values (colorHue, colorSaturation, colorTemperature). This causes
Home Assistant to not update the light color when a color scene is
triggered.

The sceneUpdated event contains the full attribute set in its actions
array. This commit adds _apply_scene_actions() which extracts those
attributes and applies them to the corresponding light entities,
ensuring HA always receives the correct color state.

Fixes sanjoyg#181

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@robertgocs-pixel
Copy link

great work, thanks :)
Works like a charm :)

nrbrt and others added 3 commits February 2, 2026 20:58
Both controllers have 2 buttons and need to be mapped so that
each button is recognized as a separate entity (_1 and _2 suffix).

Without this mapping, devices default to 1 button, causing trigger
type mismatches for multi-button controllers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The Dirigera hub reports both physical buttons (on and off) with the
same device ID suffix (_1). Setting button count to 1 to match actual
hub behavior. See issue sanjoyg#160 debug log confirmation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Keep at 2 for forward compatibility - the device has 2 physical buttons,
even though the Dirigera hub currently reports both as _1. If IKEA fixes
this in a firmware update, it will work automatically.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New devices are not automatically shown in integration

2 participants