mirror of
https://github.com/adrianjagielak/home-assistant-futurehome.git
synced 2025-10-04 02:37:10 +00:00
Use light
entity for out_lvl_switch if the device type is "light"
This commit is contained in:
parent
91c33b33cd
commit
fdc65a0bd5
@ -42,7 +42,7 @@ Some services are more common than others; some are deprecated entirely.
|
||||
| Media player | [media_player](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/media_player.ts) | | ✅ | [Select](https://www.home-assistant.io/integrations/select/), [Number](https://www.home-assistant.io/integrations/number/), [Switch](https://www.home-assistant.io/integrations/switch/), [Image](https://www.home-assistant.io/integrations/image/), [Sensor](https://www.home-assistant.io/integrations/sensor/) |
|
||||
| Meter | [meter_elec](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts), [meter_gas](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts), [meter_water](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts), [meter_heating](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts), [meter_cooling](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts) | [HAN-Sensor](https://www.futurehome.io/en/shop/han-sensor) | ✅ | [Sensor](https://www.home-assistant.io/integrations/sensor/), [Button](https://www.home-assistant.io/integrations/button/) |
|
||||
| Binary switch | [out_bin_switch](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/out_bin_switch.ts) | [16A Puck Relé](https://www.futurehome.io/en_no/shop/puck-relay-16a) | ✅ | [Switch](https://www.home-assistant.io/integrations/switch/) |
|
||||
| Level switch | [out_lvl_switch](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/out_lvl_switch.ts) | [Smart LED Dimmer](https://www.futurehome.io/en_no/shop/smart-led-dimmer-polar-white) | ✅ | [Number](https://www.home-assistant.io/integrations/number/) |
|
||||
| Level switch | [out_lvl_switch](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/out_lvl_switch.ts) | [Smart LED Dimmer](https://www.futurehome.io/en_no/shop/smart-led-dimmer-polar-white) | ✅ | [Light](https://www.home-assistant.io/integrations/light/), [Number](https://www.home-assistant.io/integrations/number/) |
|
||||
| Button | [scene_ctrl](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/scene_ctrl.ts) | [Modusbryter](https://www.futurehome.io/en_no/shop/modeswitch-white) | ✅ | [Sensor](https://www.home-assistant.io/integrations/sensor/), [Select](https://www.home-assistant.io/integrations/select/) |
|
||||
| Schedule entry | [schedule_entry](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/schedule_entry.ts) | | ✅ | [Number](https://www.home-assistant.io/integrations/number/), [Button](https://www.home-assistant.io/integrations/button/), [Binary sensor](https://www.home-assistant.io/integrations/binary_sensor/), [Sensor](https://www.home-assistant.io/integrations/sensor/) |
|
||||
| Binary sensor | [sensor_contact](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_sensor_binary.ts), [sensor_presence](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_sensor_binary.ts) | | ✅ | [Binary sensor](https://www.home-assistant.io/integrations/binary_sensor/) |
|
||||
|
@ -41,7 +41,7 @@ Some services are more common than others; some are deprecated entirely.
|
||||
| Media player | [media_player](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/media_player.ts) | | ✅ | [Select](https://www.home-assistant.io/integrations/select/), [Number](https://www.home-assistant.io/integrations/number/), [Switch](https://www.home-assistant.io/integrations/switch/), [Image](https://www.home-assistant.io/integrations/image/), [Sensor](https://www.home-assistant.io/integrations/sensor/) |
|
||||
| Meter | [meter_elec](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts), [meter_gas](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts), [meter_water](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts), [meter_heating](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts), [meter_cooling](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_meter.ts) | [HAN-Sensor](https://www.futurehome.io/en/shop/han-sensor) | ✅ | [Sensor](https://www.home-assistant.io/integrations/sensor/), [Button](https://www.home-assistant.io/integrations/button/) |
|
||||
| Binary switch | [out_bin_switch](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/out_bin_switch.ts) | [16A Puck Relé](https://www.futurehome.io/en_no/shop/puck-relay-16a) | ✅ | [Switch](https://www.home-assistant.io/integrations/switch/) |
|
||||
| Level switch | [out_lvl_switch](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/out_lvl_switch.ts) | [Smart LED Dimmer](https://www.futurehome.io/en_no/shop/smart-led-dimmer-polar-white) | ✅ | [Number](https://www.home-assistant.io/integrations/number/) |
|
||||
| Level switch | [out_lvl_switch](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/out_lvl_switch.ts) | [Smart LED Dimmer](https://www.futurehome.io/en_no/shop/smart-led-dimmer-polar-white) | ✅ | [Light](https://www.home-assistant.io/integrations/light/), [Number](https://www.home-assistant.io/integrations/number/) |
|
||||
| Button | [scene_ctrl](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/scene_ctrl.ts) | [Modusbryter](https://www.futurehome.io/en_no/shop/modeswitch-white) | ✅ | [Sensor](https://www.home-assistant.io/integrations/sensor/), [Select](https://www.home-assistant.io/integrations/select/) |
|
||||
| Schedule entry | [schedule_entry](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/schedule_entry.ts) | | ✅ | [Number](https://www.home-assistant.io/integrations/number/), [Button](https://www.home-assistant.io/integrations/button/), [Binary sensor](https://www.home-assistant.io/integrations/binary_sensor/), [Sensor](https://www.home-assistant.io/integrations/sensor/) |
|
||||
| Binary sensor | [sensor_contact](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_sensor_binary.ts), [sensor_presence](https://github.com/adrianjagielak/home-assistant-futurehome/blob/master/futurehome/src/services/_sensor_binary.ts) | | ✅ | [Binary sensor](https://www.home-assistant.io/integrations/binary_sensor/) |
|
||||
|
@ -80,9 +80,7 @@ import { pollVinculum } from './fimp/vinculum';
|
||||
const hubId = house.val.param.house.hubId;
|
||||
|
||||
const devices = await pollVinculum('device');
|
||||
log.debug(
|
||||
`FIMP devices:\n${JSON.stringify(devices, null, 0)}`,
|
||||
);
|
||||
log.debug(`FIMP devices:\n${JSON.stringify(devices, null, 0)}`);
|
||||
|
||||
const haConfig = retainedMessages.filter((msg) =>
|
||||
msg.topic.endsWith('/config'),
|
||||
@ -191,7 +189,11 @@ import { pollVinculum } from './fimp/vinculum';
|
||||
log.error('Failed publishing device', device, e);
|
||||
}
|
||||
}
|
||||
if (demoMode || thingsplexAllowEmpty || (thingsplexUsername && thingsplexPassword)) {
|
||||
if (
|
||||
demoMode ||
|
||||
thingsplexAllowEmpty ||
|
||||
(thingsplexUsername && thingsplexPassword)
|
||||
) {
|
||||
Object.assign(
|
||||
commandHandlers,
|
||||
exposeSmarthubTools({
|
||||
|
@ -2518,5 +2518,128 @@
|
||||
"props": { "sup_units": ["km/h"] }
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client": { "name": "Spisestue" },
|
||||
"fimp": { "adapter": "zwave-ad", "address": "6", "group": "ch_0" },
|
||||
"functionality": "lighting",
|
||||
"id": 1011,
|
||||
"lrn": true,
|
||||
"model": "zw_411_4_8705",
|
||||
"param": {
|
||||
"dimValue": 3,
|
||||
"energy": 49.6100006103516,
|
||||
"power": "off",
|
||||
"timestamp": "2025-09-26 18:32:21 +0200",
|
||||
"wattage": 0,
|
||||
"zwaveConfigParameters": []
|
||||
},
|
||||
"problem": false,
|
||||
"room": 1,
|
||||
"services": {
|
||||
"dev_sys": {
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:dev_sys/ad:1011_0",
|
||||
"enabled": true,
|
||||
"intf": [
|
||||
"cmd.config.get_report",
|
||||
"cmd.config.set",
|
||||
"cmd.group.add_members",
|
||||
"cmd.group.delete_members",
|
||||
"cmd.group.get_members",
|
||||
"cmd.ping.send",
|
||||
"evt.config.report",
|
||||
"evt.group.members_report",
|
||||
"evt.ping.report"
|
||||
],
|
||||
"props": { "is_secure": false, "is_unsecure": true }
|
||||
},
|
||||
"indicator_ctrl": {
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:indicator_ctrl/ad:1011_0",
|
||||
"enabled": true,
|
||||
"intf": [
|
||||
"cmd.indicator.identify",
|
||||
"cmd.indicator.set_visual_element"
|
||||
],
|
||||
"props": { "is_secure": false, "is_unsecure": true }
|
||||
},
|
||||
"meter_elec": {
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:meter_elec/ad:1011_0",
|
||||
"enabled": true,
|
||||
"intf": [
|
||||
"cmd.meter.get_report",
|
||||
"cmd.meter.reset",
|
||||
"evt.meter.report"
|
||||
],
|
||||
"props": {
|
||||
"is_secure": false,
|
||||
"is_unsecure": true,
|
||||
"sup_export_units": [],
|
||||
"sup_units": ["kWh", "W"]
|
||||
}
|
||||
},
|
||||
"out_lvl_switch": {
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:out_lvl_switch/ad:1011_0",
|
||||
"enabled": true,
|
||||
"intf": [
|
||||
"cmd.binary.set",
|
||||
"cmd.lvl.get_report",
|
||||
"cmd.lvl.set",
|
||||
"cmd.lvl.start",
|
||||
"cmd.lvl.stop",
|
||||
"evt.binary.report",
|
||||
"evt.lvl.report"
|
||||
],
|
||||
"props": {
|
||||
"is_secure": false,
|
||||
"is_unsecure": true,
|
||||
"max_lvl": 100,
|
||||
"min_lvl": 0
|
||||
}
|
||||
},
|
||||
"scene_ctrl": {
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:scene_ctrl/ad:1011_0",
|
||||
"enabled": true,
|
||||
"intf": ["evt.scene.report"],
|
||||
"props": {
|
||||
"is_secure": false,
|
||||
"is_unsecure": true,
|
||||
"sup_scenes": [
|
||||
"1.key_pressed_1_time",
|
||||
"1.key_released",
|
||||
"1.key_held_down",
|
||||
"1.key_pressed_2_times",
|
||||
"1.key_pressed_3_times",
|
||||
"1.key_pressed_4_times",
|
||||
"1.key_pressed_5_times",
|
||||
"2.key_pressed_1_time",
|
||||
"2.key_released",
|
||||
"2.key_held_down",
|
||||
"2.key_pressed_2_times",
|
||||
"2.key_pressed_3_times",
|
||||
"2.key_pressed_4_times",
|
||||
"2.key_pressed_5_times"
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": {
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:version/ad:1011_0",
|
||||
"enabled": true,
|
||||
"intf": ["cmd.version.get_report", "evt.version.report"],
|
||||
"props": { "is_secure": false, "is_unsecure": true }
|
||||
}
|
||||
},
|
||||
"supports": ["clear", "poll"],
|
||||
"thing": 1,
|
||||
"type": {
|
||||
"subtype": null,
|
||||
"supported": {
|
||||
"appliance": [],
|
||||
"blinds": [],
|
||||
"fan": [],
|
||||
"heater": [],
|
||||
"light": []
|
||||
},
|
||||
"type": "light"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -2380,5 +2380,79 @@
|
||||
"name": "sensor_wind"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1011,
|
||||
"services": [
|
||||
{
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:out_lvl_switch/ad:1011_0",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "lvl",
|
||||
"values": [
|
||||
{
|
||||
"ts": "2025-09-26 12:39:19 +0200",
|
||||
"val": 22,
|
||||
"val_t": "int"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "binary",
|
||||
"values": [
|
||||
{
|
||||
"ts": "2025-09-26 12:39:19 +0200",
|
||||
"val": true,
|
||||
"val_t": "bool"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"name": "out_lvl_switch"
|
||||
},
|
||||
{
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:dev_sys/ad:1011_0",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "state",
|
||||
"values": [
|
||||
{
|
||||
"ts": "2025-09-08 21:06:32 +0200",
|
||||
"val": "UP",
|
||||
"val_t": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"name": "dev_sys"
|
||||
},
|
||||
{
|
||||
"addr": "/rt:dev/rn:zw/ad:1/sv:meter_elec/ad:1011_0",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "meter",
|
||||
"values": [
|
||||
{
|
||||
"props": {
|
||||
"delta_t": "774",
|
||||
"prv_data": "31.290001",
|
||||
"unit": "kWh"
|
||||
},
|
||||
"ts": "2025-09-26 18:32:21 +0200",
|
||||
"val": 49.6100006103516,
|
||||
"val_t": "float"
|
||||
},
|
||||
{
|
||||
"props": { "unit": "W" },
|
||||
"ts": "2025-09-26 18:32:21 +0200",
|
||||
"val": 0,
|
||||
"val_t": "float"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"name": "meter_elec"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
VinculumPd7Service,
|
||||
} from '../fimp/vinculum_pd7_device';
|
||||
import { ServiceComponentsCreationResult } from '../ha/publish_device';
|
||||
import { haGetCachedState } from '../ha/update_state';
|
||||
|
||||
export function out_lvl_switch__components(
|
||||
topicPrefix: string,
|
||||
@ -11,11 +12,92 @@ export function out_lvl_switch__components(
|
||||
svc: VinculumPd7Service,
|
||||
_svcName: string,
|
||||
): ServiceComponentsCreationResult | undefined {
|
||||
const commandTopic = `${topicPrefix}${svc.addr}/command`;
|
||||
const lvlCommandTopic = `${topicPrefix}${svc.addr}/command`;
|
||||
const binaryCommandTopic = `${topicPrefix}${svc.addr}/binary/command`;
|
||||
const stateTopic = `${topicPrefix}/state`;
|
||||
|
||||
const minLvl = svc.props?.min_lvl ?? 0;
|
||||
const maxLvl = svc.props?.max_lvl ?? 100;
|
||||
|
||||
const isLightDevice = device.type?.type === 'light';
|
||||
|
||||
if (isLightDevice) {
|
||||
// Use light component for light devices
|
||||
return {
|
||||
components: {
|
||||
[`${svc.addr}_light`]: {
|
||||
unique_id: `${svc.addr}_light`,
|
||||
platform: 'light',
|
||||
name: 'Light',
|
||||
brightness: true,
|
||||
brightness_scale: maxLvl,
|
||||
command_topic: binaryCommandTopic,
|
||||
brightness_command_topic: lvlCommandTopic,
|
||||
optimistic: false,
|
||||
state_topic: stateTopic,
|
||||
state_value_template: `{{ (value_json['${svc.addr}'].lvl > 0) | iif('ON', 'OFF') }}`,
|
||||
brightness_state_topic: stateTopic,
|
||||
brightness_value_template: `{{ value_json['${svc.addr}'].lvl }}`,
|
||||
},
|
||||
},
|
||||
commandHandlers: {
|
||||
[lvlCommandTopic]: async (payload: string) => {
|
||||
const lvl = parseInt(payload, 10);
|
||||
if (Number.isNaN(lvl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await sendFimpMsg({
|
||||
address: svc.addr!,
|
||||
service: 'out_lvl_switch',
|
||||
cmd: 'cmd.lvl.set',
|
||||
val: lvl,
|
||||
val_t: 'int',
|
||||
});
|
||||
},
|
||||
[binaryCommandTopic]: async (payload: string) => {
|
||||
if (payload === 'ON') {
|
||||
// Skip setting to max brightness if the device is already on, because Home Assistant also sends "ON" when only changing brightness.
|
||||
const currentState = haGetCachedState({
|
||||
topic: `${topicPrefix}/state`,
|
||||
})?.[svc.addr];
|
||||
if (currentState.lvl > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (svc.intf?.includes('cmd.binary.set')) {
|
||||
// Set level to the last known non-zero value (not supported in add-on demo mode)
|
||||
await sendFimpMsg({
|
||||
address: svc.addr!,
|
||||
service: 'out_lvl_switch',
|
||||
cmd: 'cmd.binary.set',
|
||||
val: payload === 'ON',
|
||||
val_t: 'bool',
|
||||
});
|
||||
} else {
|
||||
// Set level to max brightness
|
||||
await sendFimpMsg({
|
||||
address: svc.addr!,
|
||||
service: 'out_lvl_switch',
|
||||
cmd: 'cmd.lvl.set',
|
||||
val: maxLvl,
|
||||
val_t: 'int',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await sendFimpMsg({
|
||||
address: svc.addr!,
|
||||
service: 'out_lvl_switch',
|
||||
cmd: 'cmd.lvl.set',
|
||||
val: minLvl,
|
||||
val_t: 'int',
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
} else {
|
||||
// Use number component for non-light devices
|
||||
return {
|
||||
components: {
|
||||
[svc.addr]: {
|
||||
@ -25,14 +107,14 @@ export function out_lvl_switch__components(
|
||||
min: minLvl,
|
||||
max: maxLvl,
|
||||
step: 1,
|
||||
command_topic: commandTopic,
|
||||
command_topic: lvlCommandTopic,
|
||||
optimistic: false,
|
||||
value_template: `{{ value_json['${svc.addr}'].lvl }}`,
|
||||
},
|
||||
},
|
||||
|
||||
commandHandlers: {
|
||||
[commandTopic]: async (payload: string) => {
|
||||
[lvlCommandTopic]: async (payload: string) => {
|
||||
const lvl = parseInt(payload, 10);
|
||||
if (Number.isNaN(lvl)) {
|
||||
return;
|
||||
@ -49,3 +131,4 @@ export function out_lvl_switch__components(
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user