Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Szenen #22

Open
PhilippImhof opened this issue Oct 22, 2021 · 15 comments
Open

Szenen #22

PhilippImhof opened this issue Oct 22, 2021 · 15 comments

Comments

@PhilippImhof
Copy link

PhilippImhof commented Oct 22, 2021

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?

@PhilippImhof PhilippImhof changed the title Szene Szenen Oct 24, 2021
@woodworm
Copy link
Member

Wir werden die Dokumentation kontinuierlich ausbauen 🤝

@tech-geek-4
Copy link

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
Copy link
Member

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
Copy link

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
Copy link

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
Copy link
Member

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
Copy link
Member

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

@tech-geek-4
Copy link

tech-geek-4 commented Apr 17, 2024

ups...sorry!

try this for the websocket solution

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

@tech-geek-4

This comment has been minimized.

@tech-geek-4
Copy link

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
Copy link

ReTo007 commented Apr 21, 2024

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
Copy link
Member

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
Copy link

ReTo007 commented Apr 23, 2024

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
Copy link
Member

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
Copy link

ReTo007 commented Apr 23, 2024

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

@woodworm woodworm transferred this issue from Feller-AG/wiser-tutorial May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants