From b1fb5d9417f5cce6ad9e01a3b02a29834bb1331d Mon Sep 17 00:00:00 2001 From: StumblingGamer <33354711+StumblingGamer@users.noreply.github.com> Date: Mon, 22 Jun 2026 11:03:23 -0400 Subject: [PATCH 1/2] Preserve tap action data for numeric picker actions Pass tap_action.data into numeric menu items and merge it with the selected picker value before calling the Home Assistant service. --- source/HomeAssistantMenuItemFactory.mc | 8 ++++++-- source/HomeAssistantNumericMenuItem.mc | 19 ++++++++++++++----- source/HomeAssistantView.mc | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/source/HomeAssistantMenuItemFactory.mc b/source/HomeAssistantMenuItemFactory.mc index 6ee8ba6..5060c5c 100644 --- a/source/HomeAssistantMenuItemFactory.mc +++ b/source/HomeAssistantMenuItemFactory.mc @@ -163,6 +163,7 @@ class HomeAssistantMenuItemFactory { entity_id as Lang.String?, template as Lang.String?, action as Lang.String?, + data as Lang.Dictionary?, picker as Lang.Dictionary, options as { :exit as Lang.Boolean, @@ -171,9 +172,12 @@ class HomeAssistantMenuItemFactory { :icon as WatchUi.Bitmap } ) as WatchUi.MenuItem { - var data = null; if (entity_id != null) { - data = { "entity_id" => entity_id }; + if (data == null) { + data = { "entity_id" => entity_id }; + } else { + data["entity_id"] = entity_id; + } } var keys = mMenuItemOptions.keys(); for (var i = 0; i < keys.size(); i++) { diff --git a/source/HomeAssistantNumericMenuItem.mc b/source/HomeAssistantNumericMenuItem.mc index 0fcaa25..0f22fca 100644 --- a/source/HomeAssistantNumericMenuItem.mc +++ b/source/HomeAssistantNumericMenuItem.mc @@ -155,7 +155,10 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem { // function onConfirm(b as Lang.Boolean) as Void { var dataAttribute = mPicker["data_attribute"] as Lang.String?; - var entity_id = mData["entity_id"] as Lang.String?; + var entity_id = null as Lang.String?; + if (mData != null) { + entity_id = mData["entity_id"] as Lang.String?; + } WatchUi.popView(WatchUi.SLIDE_RIGHT); WatchUi.requestUpdate(); @@ -164,12 +167,18 @@ class HomeAssistantNumericMenuItem extends HomeAssistantMenuItem { return; } if (mAction != null) { + var data = {} as Lang.Dictionary; + if (mData != null) { + var keys = mData.keys(); + for (var i = 0; i < keys.size(); i++) { + data[keys[i]] = mData[keys[i]]; + } + } + data["entity_id"] = entity_id.toString(); + data[dataAttribute.toString()] = mValue; mHomeAssistantService.call( mAction, - { - "entity_id" => entity_id.toString(), - dataAttribute.toString() => mValue - }, + data, mExit ); } diff --git a/source/HomeAssistantView.mc b/source/HomeAssistantView.mc index 0d86b9a..60c8cff 100644 --- a/source/HomeAssistantView.mc +++ b/source/HomeAssistantView.mc @@ -141,6 +141,7 @@ class HomeAssistantView extends WatchUi.Menu2 { entity, content, action, + data, picker, { :exit => exit, From 17690d43499e927898a738b9cee53fa9c1bc05bc Mon Sep 17 00:00:00 2001 From: StumblingGamer <33354711+StumblingGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 11:12:00 -0400 Subject: [PATCH 2/2] Proposing changes to documentation and JSON Schema Added proposed documentation section explaining Numeric data object and also updated JSON schema to match changes. I tested the numeric example with tap_action.data in the documented web editor. The current schema did not appear to reject the field, likely because numeric tap_action does not currently forbid additional properties at that nested level. I still added data explicitly to the numeric schema so it is documented, discoverable, and type-checked as an object. --- config.schema.json | 5 +++++ examples/Numeric.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/config.schema.json b/config.schema.json index 1ad8e64..01f701c 100644 --- a/config.schema.json +++ b/config.schema.json @@ -256,6 +256,11 @@ "action": { "$ref": "#/$defs/action" }, + "data": { + "type": "object", + "title": "Additional action data", + "description": "Fixed Home Assistant service data. The selected picker value is merged into this object using the picker's data_attribute. Service-specific fields cannot be schema checked here." + }, "picker": { "type": "object", "title": "Number picker configuration", diff --git a/examples/Numeric.md b/examples/Numeric.md index 878b442..97af375 100644 --- a/examples/Numeric.md +++ b/examples/Numeric.md @@ -39,6 +39,36 @@ Field | Purpose It may well be the case that often `attribute` and `data_attribute` are the same attribute, as with this example. +## Additional Action Data + +The `tap_action` object may also include a `data` object for fixed service call parameters. When the picker value is selected, the application merges the picker value into this `data` object using `data_attribute`. + +For example, a light brightness picker can request a HomeAssistant transition while still using the picker value for `brightness`. + +```json +{ + "name": "Lounge Brightness", + "content": "{{ ((state_attr('light.lounge','brightness') | int(0) / 255) * 100) | round(0) }}%", + "type": "numeric", + "entity": "light.lounge", + "tap_action": { + "action": "light.turn_on", + "data": { + "transition": 2 + }, + "picker": { + "step": 5, + "min": 0, + "max": 255, + "attribute": "brightness", + "data_attribute": "brightness" + } + } +} +``` + +The resulting action data sent to HomeAssistant contains both the fixed `transition` value and the selected `brightness` value. + ## Helper You might define a "helper" entity as follows in HomeAssistant: