Feller-AG / wiser-api

MIT License
12 stars 1 forks source link

Szenen #22

Open PhilippImhof opened 2 years ago

PhilippImhof commented 2 years ago

Danke für die Beschreibung der API. Das bietet einen echten Mehrwert.

Interessant wäre, wenn sie auch die Details zu /api/scenes bzw. /api/jobs beschreiben könnten. Ist das geplant?

woodworm commented 2 years ago

Wir werden die Dokumentation kontinuierlich ausbauen 🤝

tech-geek-4 commented 2 months ago

Gibt es für Szenen allenfalls auch die Möglichkeit, das drücken eines Szenentasters über WebSocket weiter zu verarbeiten?

Ich würde gerne Szenentaster einbauen, diese aber nachher in Homeassistant nutzen.

Die einzige Variante die ich gerade sehe, wäre mit dem Szenentaster ein Script auszuführen und dieses dann in HA abzufragen.

woodworm commented 2 months ago

You can upload or create the script example below on the script website. You can then link the script to as many SmartButtons as you want by clicking on “Link to SmartButton”.

from sf.lib import alog
import websockets

async def onButtonEvent(*argv):
    await alog('SmartButton_%d %s', argv[2], argv[0])
    await websockets.push_event('/api', {'smb': {'cmd': argv[0], 'type': argv[1], 'id': argv[2]}})
tech-geek-4 commented 2 months ago

Thanks for your fast reply.

Unfortunately i get the following error message:

Traceback (most recent call last): File "gateway/api/scripts.py", line 86, in try_function File "var/www/scripts/websocket.py", line 10, in onStart AttributeError: 'module' object has no attribute 'push_event'

Do you have any idea what could be wrong?

tech-geek-4 commented 2 months ago

I tried as well via webhook command to HA. But then i get a error message about the certificate although i try not to verify it...

from sf.lib import aiocurl, alog

webhookid = 'webhook-id'  # Webhook ID out of HA
url = 'https://my-url.ch/api/webhook/' + 'webhookid'
headers = {'Content-Type': 'application/json'}
data = '{"key": value1}'

async def onButtonEvent(*argv):
    await alog('%s %s on smartbutton %s', argv[0], argv[1], argv[2])
    await alog('POST %s %s', url, data)
    await aiocurl(url, method='POST', body=data, headers=headers, verify=False)

# Called from the Web-GUI 'start'-button
async def onStart(*argv):
    await alog(str(argv))

    await aiocurl(url, method='POST', body=data, headers=headers, verify=False)
woodworm commented 2 months ago

ups...sorry! try this for the websocket solution

from sf.lib import alog
import websockets

async def onButtonEvent(*argv):
    await alog('SmartButton_%d %s', argv[2], argv[0])
    try:
        await websockets.Connection.push_event('/api', {'smb': {'cmd': argv[0], 'type': argv[1], 'id': argv[2]}})
    except AttributeError: 
        await websockets.push_event('/api', {'smb': {'cmd': argv[0], 'type': argv[1], 'id': argv[2]}})
woodworm commented 2 months ago

For https you need a certificate. It might be easier if you just use http instead of https.

tech-geek-4 commented 2 months ago

ups...sorry!

try this for the websocket solution

Works like a charm! Thanks a lot for the fast help!

tech-geek-4 commented 2 months ago

For https you need a certificate.

It might be easier if you just use http instead of https.

~~I do have a certificate. But for an unknown it seems it doesn't accept it.

Is there any way to inhibit the certificate-check?

Would be easier than to reconfigure the server.~~

tech-geek-4 commented 2 months ago

For https you need a certificate.

It might be easier if you just use http instead of https.

I do have a certificate. But for an unknown it seems it doesn't accept it.

Is there any way to inhibit the certificate-check?

Would be easier than to reconfigure the server...😉

Disregard, i reconfiguerd to get the http through which works great now. For the usage in HA webhooks works great and almost easier than WS. But would of course be great to have the functionality directly implemented in the upcoming MQTT capability...😉

Btw: Congrats to your new and improved product lineup! 💪

ReTo007 commented 2 months ago

You can upload or create the script example below on the script website. You can then link the script to as many SmartButtons as you want by clicking on “Link to SmartButton”.

from sf.lib import alog
import websockets

async def onButtonEvent(*argv):
    await alog('SmartButton_%d %s', argv[2], argv[0])
    await websockets.push_event('/api', {'smb': {'cmd': argv[0], 'type': argv[1], 'id': argv[2]}})

@woodworm Works indeed very well 😀 Any chance to distinguish between a short button press, a long button press, and/or a double click? For me it's alway "click", "play", and "button number".

woodworm commented 2 months ago

The whole thing depends on the button type. Scene-buttons only send “click” events for "play and "record". Ctrl-buttons (+/-. I/0, ^/v) can send click, press and release for up and down buttons

ReTo007 commented 2 months ago

Thanks, woodworm. I see... Indeed I was using a scene button. What makes the difference between "play" and "record" events? When would the button send a "record" event?

woodworm commented 2 months ago

This depends on the FW version of the device. Older FWs send a “record” event after pressing the button for 5 seconds and newer FWs after 10 seconds. Additionally, {“recordable”: true} must be set in the SmartButton object.

curl -X PATCH http://192.168.0.232/api/smartbuttons/2112 -H 'Content-Type:application/json' -d '{"recordable":true}'

ReTo007 commented 2 months ago

Interesting - will give that a try in the next few days 😀 Many thanks for the explanations!