How to create a push button
Closed this issue · 2 comments
apiel commented
I try to create a push button but I can't figure out how it work:
function makeThing() {
const thing = new Thing(
'urn:dev:ops:my-switchbot-1234',
'Switchbot',
['PushButton'],
'Trigger Switchbot',
);
thing.addProperty(
new Property(
thing,
'pushed',
new Value(true, (update) => {
console.log(`change: ${update}`);
if (update === 'pushed') {
switchbot.press();
}
}),
{
'@type': 'PushedProperty',
title: 'Switchbot',
type: 'boolean',
description: 'Press switchbot',
},
),
);
return thing;
}
But clicking on the icon doesn't trigger any event... I just need a sinple push button, with a sinle press (no on/off).
How can fix this? Is there some example somewhere? Is there better documentation than https://iot.mozilla.org/schemas/ ?
mrstegeman commented
A PushButton refers to an actual hardware push button. You would not control such a device through software, so the PushedProperty is always treated as read-only by the UI. What you want is an OnOffSwitch. Your web thing could treat it as a momentary switch that would switch back off after some short time period.
kgiori commented