Skip to content

fix: Home Assistant: allow to override discovery type - #32549

Closed
Koenkk wants to merge 1 commit into
devfrom
fix/ha-type
Closed

Koenkk wants to merge 1 commit into
devfrom
fix/ha-type

Conversation

@Koenkk

@Koenkk Koenkk commented Jul 12, 2026

Copy link
Copy Markdown
Owner

This PR enables overriding the HA discovery type through expose.withHomeAssistant(). Implemented for the use-case of @jbouwh to expose IR entities, example:

e.text("ir_code_to_send", ea.SET).withDescription("The IR code or timings to send by device").withHomeAssistant({type: "infrared"})

The type overrides the the type in the topic on which the HA discovery payload is published.

CC: @MaxRink

@jbouwh

jbouwh commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

We need 2 different entities for IR emitter and receiver. These entities will also require a schema setting: home-assistant/core#172796

@jbouwh

jbouwh commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

If the schema property can be added and the value_template be customized like this:

diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts
index b1185cb0..01730a37 100644
--- a/lib/extension/homeassistant.ts
+++ b/lib/extension/homeassistant.ts
@@ -381,6 +381,10 @@ const applyHomeAssistantExposeMetadata = (payload: DiscoveryEntry, homeAssistant
         payload.type = homeAssistant.type;
     }
 
+    if (homeAssistant.property !== undefined) {
+        payload.discovery_payload.schema = homeAssistant.schema;
+    }
+
     if (homeAssistant.entityCategory !== undefined) {
         payload.discovery_payload.entity_category = homeAssistant.entityCategory;
     }
@@ -1424,6 +1428,14 @@ export class HomeAssistant extends Extension {
                 delete entry.discovery_payload.entity_category;
             }
 
+            if (entry.type === "infrared") {
+                if (entry.discovery_payload.schema === "receiver") {
+                    entry.discovery_payload.value_template = "{{ value_json.learned_ir_timings | tojson }}";
+                } else {
+                    delete entry.discovery_payload.value_template;
+                }
+            }
+
             // Let Home Assistant generate entity name when device_class is present.
             // preserve_name allows device_class and explicit name to coexist (e.g. derived sensors).
             if (entry.discovery_payload.device_class && !NUMERIC_DISCOVERY_LOOKUP[firstExpose.name]?.preserve_name) {

Then this could work.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions Bot added the stale Stale issues label Sep 16, 2026
@Koenkk Koenkk closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants