Momentary switch Habpanel

Hi, Can somebody help me please?

I need to have een so called momentary switch in habpanel.
As example : When i push a button the item goes ON, when i let it go the item goes off.

Item is modbus device that now is working push is on and second push is off

Is this possible? Or is there another method to do this.

Thanks in advance.
Mickel

You could maybe look into on-click and on-release events. ON on click and OFF on release. Might be able to simulate a momentary switch.

Mikael

Edit: correct names for the events are onmousedown and onmouseup…

ng-mousedown and ng-mouseup work:

<div style="position: absolute; cursor: pointer; display: flex; top: 0; left: 0; width: 100%; height: 100%;"
     ng-style="{ 'background-color': itemState('Test_Item') === 'ON' ? 'turquoise' : 'teal' }"
     ng-mousedown="sendCmd('Test_Item', 'ON')" ng-mouseup="sendCmd('Test_Item', 'OFF')">
  <div style="margin: auto">
	Hold me
  </div>
</div>

Adjust to your needs and/or use custom widget settings.

1 Like

Hi together,

i just uses the code from ysc.
It works some times but in some cases the status stays. It seems that the OFF signal will be not accepted.
Also when i hold the button it doesnt hold the status. Is the force auto update in the item (Paper UI) which i want to switch maybe the solution?
Has mickelluiten success with his project?