Feller-AG / wiser-api

MIT License
12 stars 1 forks source link

Trigger job with button_ctrl with a smartbutton ? #9

Open sulazix opened 1 year ago

sulazix commented 1 year ago

I created a job with a button_ctrl property : /api/jobs

body = {"button_ctrl": {
        "button" : "toggle",
        "event": "on",
        "loads": [load_id]}
}

Reponse => [...] job_id = #51

Then tried to link this job to a smartbutton (a scene one not a grp_ctrl) : 1) /api/smartbuttons/program =>

    body = {
        "on": True,
        "timeout": 10,
        "button_type": "scene",
        "owner" : "all",
        }

2) /api/smartbuttons/notify

    body = {
        "on": True,
        "timeout": 60,
        "button_type": "scene",
        "owner" : "all",
        }

3) Assign the job to the smartbutton : /api/smartbuttons/{id} (<-smart button id = 43) body = {"job": job_id} <- here job_id = 51

All requests returns 200.

Is it : a) impossible to trigger a "button_ctrl" from a scene (the system is designed as such) or b) i'm doing a mistake ?

I naturally tested the job alone with /api/jobs/{id}/trigger and it works.

To bypass this problem I created a script to call the trigger action through the API

id = 16 #load ID
token = "Don't want to write it here :-)" 
headers = {'Authorization': 'Bearer {0}'.format(token)}
host = '10.0.0.145' 

async def onButtonEvent(*argv):
    await alog('%s %s on smartbutton %s', argv[0], argv[1], argv[2])
    body = '{"button" : "toggle", "event": "click"}'
    #body = '{"on": true}'
    url = 'http://' + host + '/api/loads/{id}/ctrl'.format(id=id)
    ret = await aiocurl(url, method='PUT', body=body, headers=headers)

It's working but with three main drawback : 1) I can't use localhost or 127.0.0.1 to connect to the API instead of API (OSError: [Errno 111] ECONNREFUSED , the socket refuse the connection) 2) If I restart my wifi router, the gateway get a new IP and I have to adjust the script 3) If there's no wifi connection it won't work

Is it possible to tell me : 1) if it is possible to attach a job with button_ctrl to a smartbutton (scene type) or not ? Did I made a misstake in the first part ? 2) If it is possible to allow connection from localhost to the API ? I think it can add a lot of flexibility in use / programming ;-)

For the IP issue see my other issue :-) #8

Regards !

oliver-joos commented 1 year ago

Thank you for reporting this issue!

I confirm that with the current firmware v5.1.27 (or older) a script with access to localhost or 127.0.0.1 leads to OSError: [Errno 111] ECONNREFUSED. I am working on this and am confident that a fix will be included in the next release.

woodworm commented 1 year ago

To trigger a job with a Scene-SmartButton, you need a job like this:

"target_states": [
        {
              "load": 1,
              "bri": 10000
        },
        {
              "load": 2,
              "bri": 10000
        }
]

When the Scene-SmartButton is pressed, the load 1 and 2 jumps to 100%.

To trigger a job with a GroupCtrl-SmartButton, you need a job like this:

"button_ctrl": {
        "loads": [1 ,2]}
}

With the GroupCtrl-SmartButton you can now switch the loads on and off (short-press) or dim them up and down (long-press).

woodworm commented 1 year ago

here you can find more information...

Lets use a smartbutton and get it married with a job.

sulazix commented 1 year ago

Thank you for reporting this issue!

I confirm that with the current firmware v5.1.27 (or older) a script with access to localhost or 127.0.0.1 leads to OSError: [Errno 111] ECONNREFUSED. I am working on this and am confident that a fix will be included in the next release.

Thanks a lot !

@woodworm sorry about the confusion I wasn't 100% clear with the name you use for each type of Object button/ctrl/... so, if I understand right :

oliver-joos commented 1 year ago

Exactly! It is not possible to trigger the button_ctrl part of a job using a SmartButton with button_type "scene" or vice versa.

Please note that the default button_type is "scene"! To trigger the button_ctrl part of a job, you must explicitly set button_type to "groupctrl". (This naming has grown historically and is therefore not very obvious)

sulazix commented 8 months ago

Thank you for reporting this issue!

I confirm that with the current firmware v5.1.27 (or older) a script with access to localhost or 127.0.0.1 leads to OSError: [Errno 111] ECONNREFUSED. I am working on this and am confident that a fix will be included in the next release.

@oliver-joos Do you know when the new firmware will be available? The "cloud update" button tells me that my firmware is up to date, but I have version 5.1.25-0. Thanks in advance for your reply. Is there any way of obtaining the firmware manually?