Skip to content

Commit

Permalink
Merge pull request #54 from alydersen/feature/dim_duration
Browse files Browse the repository at this point in the history
Adding dimming duration, updating docs and bump to 1.1.0
  • Loading branch information
alydersen authored Dec 3, 2022
2 parents 3c741da + d448300 commit f35c46c
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .homeychangelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,8 @@
},
"1.0.9": {
"en": "Adding DLP Panels as temperature sensors"
},
"1.1.0": {
"en": "Dimming durations on flows (gradually turning on dimmers over x seconds)"
}
}
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "com.github.alydersen.hdl-smartbus-homey",
"version": "1.0.9",
"version": "1.1.0",
"compatibility": ">=5.0.0",
"sdk": 3,
"name": {
Expand Down
3 changes: 3 additions & 0 deletions DEVICES_DIMMERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ A dimmer controller have one or more dimmers as channels. Different HDL Models h

Dimmers are a built-in capability in Homey, and as such have very good Homey support.

# Dimming with a duration
The dimmers supports going from the current dimming level to a new level over a time span when defined in a flow. This means that you can e.g. dim up your lights in the bedroom from off to 100% in intervals over 60 seconds. Notice that it always will be divided into 10 chunks. So in the bedroom example above, that would mean that it would increment with 10% every 6 seconds. You can also dim down over a period of time, but as flow generally will not care what the level is before it starts, you can only be sure that it will end up at what dimming level you set in the flow. These kind of calls are asyncronous, meaning that it will allow the app to act normally and update other devices while this is going on.

## Good to know
Homey operates with a dimming level of 0-100, whereas HDL operates with 0 to 1. This means that HDLs state of a dimmer channel of 0.4 will be equall to Homeys 40 (this is handled by the app). Dimmers in Homey can also receive simple ON/OFF, and the app fixes this by calling the "OFF" state when dim level is 0 and "ON" when everything above.
10 changes: 10 additions & 0 deletions DEVICES_PANELS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Back to the main page](index.md)

# DLP Panels
Even though the panels have a lot of functionality, they are only available as temperature sensors in this app. This is because of the complex nature of the DLPs and bridging this with Homey. As temperature sensors, they match a built-in capability in Homey, and as such have very good Homey support.

## How signals are received
First of all, temperature sensors are one-way only, meanings readings come from the HDL side and are set in Homey. You can not send anything back to the panel. The sensors are sending out updates with semi-regular intervals, and usually when changes in temperature occurs. I would generally not recommend trusting readings to be very fast, if you need logic that responds quickly to changes in temperature.

## Temperature scope
The app will disregard any readings that are below -40 or above 70 degrees celsius.
2 changes: 1 addition & 1 deletion DEVICES_TEMPSENSORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Temperature sensors are a built-in capability in Homey, and as such have very go
First of all, temperature sensors are one-way only, meanings readings come from the HDL side and are set in Homey. You can not send anything back to the sensor. The sensors are sending out updates with semi-regular intervals, and usually when changes in temperature occurs. I would generally not recommend trusting readings to be very fast, if you need logic that responds quickly to changes in temperature.

## Noisy sensors
Temperature sensors that are mot properly set up can be very noisy on teh bus, meaning that they will sned out a lot of updates. If you have a four-channel sensor with some channels not being connected to a physical temperature probe, remember to disable the channel in your HDL configuration. This also makes sense because the readings will be way off if there is nothing connected.
Temperature sensors that are mot properly set up can be very noisy on the bus, meaning that they will send out a lot of updates. If you have a four-channel sensor with some channels not being connected to a physical temperature probe, remember to disable the channel in your HDL configuration. This also makes sense because the readings will be way off if there is nothing connected.

## Temperature scope
The app will disregard any readings that are below -40 or above 70 degrees celsius.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ include:
- DEVICES_RELAYS.md
- DEVICES_TEMPSENSORS.md
- DEVICES_UVSWITCHES.md
- DEVICES_PANELS.md
10 changes: 9 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_comment": "This file is generated. Please edit .homeycompose/app.json instead.",
"id": "com.github.alydersen.hdl-smartbus-homey",
"version": "1.0.9",
"version": "1.1.0",
"compatibility": ">=5.0.0",
"sdk": 3,
"name": {
Expand Down Expand Up @@ -101,6 +101,14 @@
"dim",
"onoff"
],
"capabilitiesOptions": {
"dim": {
"duration": true
},
"onoff": {
"setOnDim": false
}
},
"icon": "/drivers/dimmer/assets/icon.svg",
"images": {
"large": "/drivers/dimmer/assets/images/large.png",
Expand Down
36 changes: 26 additions & 10 deletions drivers/dimmer/device.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Homey = require("homey");
const DEFAULT_DIM_DURATION = 0

class DimmerDevice extends Homey.Device {

Expand All @@ -13,7 +14,14 @@ class DimmerDevice extends Homey.Device {

// register a capability listener
this.registerCapabilityListener("onoff", this.onCapabilityOnoff.bind(this));
this.registerCapabilityListener("dim", this.onCapabilityDim.bind(this));
this.registerCapabilityListener("dim", async (value, options) => {
await this.onCapabilityDim({
level: value,
duration: typeof options.duration === "number"
? options.duration
: DEFAULT_DIM_DURATION,
});
});

// Ask for channel status
if (this.homey.app.isBusConnected()) { this.requestUpdate() }
Expand All @@ -37,13 +45,13 @@ class DimmerDevice extends Homey.Device {
}

async updateDeviceByBus(level) {
this._controller().send(
this.homey.app.controller().send(
{
target: this.getData().address,
command: 0x0031,
data: {
channel: this.getData().channel,
level: level
level: level * 100
}
},
function(err) {
Expand All @@ -54,16 +62,24 @@ class DimmerDevice extends Homey.Device {
);
}

async onCapabilityOnoff(value, opts) {
let level = value === true ? 100 : 0;
let dimlevel = value === true ? 1 : 0;
async onCapabilityOnoff(value) {
let level = value === true ? 1 : 0;
this.updateDeviceByBus(level);
this.setCapabilityValue("dim", dimlevel).catch(this.error);
this.setCapabilityValue("dim", level).catch(this.error);
}

async onCapabilityDim(value, opts) {
this.updateDeviceByBus(value * 100);
this.setCapabilityValue("onoff", value > 0).catch(this.error);
async onCapabilityDim(opts) {
var dev = this;
await this.setCapabilityValue("onoff", opts.level > 0).catch(this.error);
if (opts.duration === 0) {
dev.updateDeviceByBus(opts.level);
} else {
var current_level = await this.getCapabilityValue("dim");
var step = (opts.level - current_level) / 10;
[ ...Array(10) ].forEach(async (e, i) => {
setTimeout(function () {dev.updateDeviceByBus(current_level + (step * (i+1)))}, (opts.duration / 10) * i);
});
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions drivers/dimmer/driver.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"dim",
"onoff"
],
"capabilitiesOptions": {
"dim": { "duration": true },
"onoff": { "setOnDim": false }
},
"icon": "/drivers/dimmer/assets/icon.svg",
"images": {
"large": "/drivers/dimmer/assets/images/large.png",
Expand Down
3 changes: 2 additions & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ Devices broadcasts their state on the bus and the Homey App reads them and updat
- [Universal Switches](DEVICES_UVSWITCHES.md)
- [Multisensors](DEVICES_MULTISENSORS.md)
- [Curtain Controllers](DEVICES_CURTAINS.md)
- [Floor Heater Controllers](DEVICES_FLOORHEATERS.md)
- [Floor Heater Controllers](DEVICES_FLOORHEATERS.md)
- [DLP Panels](DEVICES_PANELS.md)
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.github.alydersen.homey-smartbus",
"version": "1.0.9",
"version": "1.1.0",
"main": "app.js",
"devDependencies": {
"@types/homey": "npm:homey-apps-sdk-v3-types@^0.3.1"
Expand Down

0 comments on commit f35c46c

Please sign in to comment.