diff --git a/README.md b/README.md index 954cca6..134b541 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ todo periodical refresh of state | alarm_weather | | | | appliance | | | | barrier_ctrl | | | -| basic | | | +| basic | | ✅ | | battery | | ✅ | | blinds | | | | boiler | | | @@ -137,7 +137,8 @@ todo periodical refresh of state | indicator_ctrl | | | | ota | | | | parameters | | | -| dev_sys | | | | technology_specific | | | + | time | | | | version | | | +| dev_sys | | | diff --git a/futurehome/config.yaml b/futurehome/config.yaml index 82bbb1c..416fb2e 100644 --- a/futurehome/config.yaml +++ b/futurehome/config.yaml @@ -1,6 +1,6 @@ # https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config name: Futurehome -version: "0.0.19" +version: "0.0.20" slug: futurehome description: Local Futurehome Smarthub integration url: "https://github.com/adrianjagielak/home-assistant-futurehome" diff --git a/futurehome/src/ha/publish_device.ts b/futurehome/src/ha/publish_device.ts index e149f77..a6209e8 100644 --- a/futurehome/src/ha/publish_device.ts +++ b/futurehome/src/ha/publish_device.ts @@ -1,6 +1,7 @@ import { InclusionReport } from "../fimp/inclusion_report"; import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device"; import { log } from "../logger"; +import { basic__components } from "../services/basic"; import { battery__components } from "../services/battery"; import { out_bin_switch__components } from "../services/out_bin_switch"; import { out_lvl_switch__components } from "../services/out_lvl_switch"; @@ -157,6 +158,7 @@ export type CommandHandlers = { [topic: string]: (payload: string) => Promise ServiceComponentsCreationResult | undefined } = { + basic: basic__components, battery: battery__components, out_bin_switch: out_bin_switch__components, out_lvl_switch: out_lvl_switch__components, diff --git a/futurehome/src/services/basic.ts b/futurehome/src/services/basic.ts new file mode 100644 index 0000000..b3fc867 --- /dev/null +++ b/futurehome/src/services/basic.ts @@ -0,0 +1,56 @@ +// Maps a Futurehome “basic” service to one MQTT *number* entity. +// ─────────────────────────────────────────────────────────────── +// FIMP ➞ HA state path used by the template +// value_json[svc.addr].lvl – current level (0-255) +// +// HA ➞ FIMP commands +// command_topic → cmd.lvl.set +// ─────────────────────────────────────────────────────────────── + +import { sendFimpMsg } from "../fimp/fimp"; +import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device"; +import { ServiceComponentsCreationResult } from "../ha/publish_device"; + +export function basic__components( + topicPrefix: string, + _device: VinculumPd7Device, + svc: VinculumPd7Service +): ServiceComponentsCreationResult | undefined { + // MQTT topic that HA will publish commands to + const cmdTopic = `${topicPrefix}${svc.addr}/command`; + + // Z-Wave “Basic” uses a 0-255 range (0 = off, 255 = on, 1-254 = dim level) + const MIN_LVL = 0; + const MAX_LVL = 255; + + return { + components: { + [svc.addr]: { + unique_id: svc.addr, + p: "number", + min: MIN_LVL, + max: MAX_LVL, + step: 1, + command_topic: cmdTopic, + optimistic: true, + value_template: `{{ value_json['${svc.addr}'].lvl }}`, + }, + }, + + // ─────── HA → FIMP bridge ─────── + commandHandlers: { + [cmdTopic]: async (payload: string) => { + const lvl = parseInt(payload, 10); + if (Number.isNaN(lvl)) return; + + await sendFimpMsg({ + address: svc.addr!, + service: "basic", + cmd: "cmd.lvl.set", + val_t: "int", + val: lvl, + }); + }, + }, + }; +}