Jump to content
🌟 NOTIFICATION/Benachrichtigung: Welcome to our New Store! - shelly.com 🌟 ×

API call to start/stop dimming?


Recommended Posts

I was inspired by this script emulate_multiple_dimmers.js to let button switches control the dimmers and got it working for turning on/off and setting brightness:

curl "http://x.x.x.x/light/0?turn=on&brightness=100"

However these dimming commands from the script have no effect (script is written for Shelly Dimmer 2, and the command is mentioned in that API)

curl "http://x.x.x.x/light/0?turn=on&dim=up&step=5"
curl "http://x.x.x.x/light/0?dim=stop"

I cannot find any similar API command for the Pro Dimmer, is there any similar way to do this? Its not documented here or here how to control dim up/down.

Link to comment
Share on other sites

  • 2 weeks later...
  • QA members
On 6/25/2024 at 8:17 PM, DHa said:
On 6/25/2024 at 8:17 PM, DHa said:

I was inspired by this script emulate_multiple_dimmers.js to let button switches control the dimmers and got it working for turning on/off and setting brightness:

curl "http://x.x.x.x/light/0?turn=on&brightness=100"

However these dimming commands from the script have no effect (script is written for Shelly Dimmer 2, and the command is mentioned in that API)

curl "http://x.x.x.x/light/0?turn=on&dim=up&step=5"
curl "http://x.x.x.x/light/0?dim=stop"

I cannot find any similar API command for the Pro Dimmer, is there any similar way to do this? Its not documented here or here how to control dim up/down.

 

It was added with the 1.4.0 beta firmware.

You just need to add rpc to the dim commands.

/rpc/Light.DimStop?id=0
/rpc/Light.DimDown?id=0&fade_rate=4
/rpc/Light.DimUp?id=0&fade_rate=4

Link to comment
Share on other sites

  • 3 months later...
  1. Make sure your firmware is up to date, those commands are not working on shipping firmware
  2. Try a simple call like turning the light on/off by calling the rpc url from your browser
    e.g. http://192.168.###.###/rpc/Light.Toggle?id=0
    or http://192.168.###.###/rpc/Light.Set?id=0&on=true&brightness=30&transition_duration=1
    --> replace the ### according to your shelly dimmer IP
  3. Try Dimming commands
    http://192.168.###.###/rpc/Light.DimDown?id=0&fade_rate=3

Also, DimUp/Down commands will initiate dimming but stop as soon as DimStop or another command has been received, so a running script that is sending calls perpetually might abort your dimming

 

Link to comment
Share on other sites

On 23.10.2024 at 23:24, Marrt said:
  1. Make sure your firmware is up to date, those commands are not working on shipping firmware
  2. Try a simple call like turning the light on/off by calling the rpc url from your browser
    e.g. http://192.168.###.###/rpc/Light.Toggle?id=0
    or http://192.168.###.###/rpc/Light.Set?id=0&on=true&brightness=30&transition_duration=1
    --> replace the ### according to your shelly dimmer IP
  3. Try Dimming commands
    http://192.168.###.###/rpc/Light.DimDown?id=0&fade_rate=3

Also, DimUp/Down commands will initiate dimming but stop as soon as DimStop or another command has been received, so a running script that is sending calls perpetually might abort your dimming

I'm new to this forum, but very interested in having this working. However when I call the url, I get a 'not found' response.

I update my shelly dimmer to verion: 20231107-164738/v1.14.1-rc1-g0617c15
did a reboot to be sure.
and called this url from a blank webpage: 192.168.xxx.xxx/rpc/Light.Toggle?id=0
note I replaced 'xxx' with my shelly dimmer ip.

Do you've any idea why I get the not found response?

Link to comment
Share on other sites

On 23.10.2024 at 23:24, Marrt said:
  1. Make sure your firmware is up to date, those commands are not working on shipping firmware
  2. Try a simple call like turning the light on/off by calling the rpc url from your browser
    e.g. http://192.168.###.###/rpc/Light.Toggle?id=0
    or http://192.168.###.###/rpc/Light.Set?id=0&on=true&brightness=30&transition_duration=1
    --> replace the ### according to your shelly dimmer IP
  3. Try Dimming commands
    http://192.168.###.###/rpc/Light.DimDown?id=0&fade_rate=3

Also, DimUp/Down commands will initiate dimming but stop as soon as DimStop or another command has been received, so a running script that is sending calls perpetually might abort your dimming

 

Late reply, but thanks! The RPC API does the trick.

Sharing my script in case it helps anyone else. It is used with both:

- push buttons connected to Shelly i4 to control Pro Dimmer 2PM remotely (dimmers need static IP)

- push buttons directly connected to Pro Dimmer 2PM inputs (localhost IP used in this case, set input/output to 'detached' mode)

The script allows controlling multiple channels from a single button, in my case I use it to have 'most lamps on/all lamps off'-buttons.

// calls to all entries (i) in control[button] are made to
// <baseUrl><control[button][i].ip>/rpc/Light.<Set/DimUp/DimDown/DimStop>?id=<control[button][i].id><xAction[button]>

// Assumes push buttons are connected to inputs as (input mode being 'button'):
// 0: on button
// 1: off button
// 2: on button
// 3: off button

// CONFIG START

let baseUrl = 'http://'
let control = [
    [
        {ip:'localhost', id:0} // lamp 3
    ],
    [
        {ip:'localhost', id:0} // lamp 3
    ],
    [
        {ip:'192.168.1.10', id:0}, // lamp 1
        {ip:'192.168.1.11', id:1}, // lamp 2
        {ip:'localhost', id:0} // lamp 3
    ],
    [
        {ip:'192.168.1.10', id:0}, // lamp 1
        {ip:'192.168.1.11', id:1}, // lamp 2
        {ip:'localhost', id:0} // lamp 3
    ]
];

let singleAction = [
    "&on=true",
    "&on=false",
    "&on=true",
    "&on=false"
]

let doubleAction = [
    '&on=true&brightness=100',
    '&on=false',
    '&on=true&brightness=100',
    '&on=false'
]

let tripleAction = [
    '&on=true&brightness=50',
    '&on=true&brightness=25',
    '&on=true&brightness=50',
    '&on=true&brightness=25',
]

let longCommand = [
    'DimUp',
    'DimDown',
    'DimUp',
    'DimDown'
]

let longSettings = [
    '&fade_rate=5',
    '&fade_rate=5',
    '&fade_rate=5',
    '&fade_rate=5'
]

// CONFIG END

let dimstate = [
    false,
    false,
    false,
    false
];

function callDimmers(button, command, settings) {
    for (let i in control[button]) {
        let ip = control[button][i].ip;
        let id = control[button][i].id;
        Shelly.call('http.get',
            { url: baseUrl + ip + '/rpc/Light.' + command + '?id=' + id + settings},
              function (response, error_code, error_message) {},
              null
        );
    }
}

function action(button, event) {
    if (dimstate[button] === true && event === 'btn_up') {
        dimstate[button] = false;
        callDimmers(button, "DimStop", "")
    } else if (event === 'single_push') {
        callDimmers(button, "Set", singleAction[button])
    } else if (event === 'double_push') {
        callDimmers(button, "Set", doubleAction[button])
    } else if (event === 'triple_push') {
        callDimmers(button, "Set", tripleAction[button])
    } else if (event === 'long_push') {
        dimstate[button] = true;
        callDimmers(button, longCommand[button], longSettings[button])
    }
}

// add an evenHandler for button type input and various push events
Shelly.addEventHandler(
    function (e) {
        action(e.id, e.info.event)
        return true;
    }
);

 

Edited by DHa
Clarifications
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...