Add support for switches to scenes

Hi Pierre-Gilles,

I have just added the ability to turn switches on and off in scenes.

It’s functional, I can now turn on a connected socket via the Xiaomi button! However, it slows down the dropdown menu. I was thinking of combining it with the turn on and turn off actions for lights, as it’s essentially the same action behind the scenes.
This is where I’m stuck; I don’t know how to retrieve both types of devices (light and switch) at the same time via the get request:

class TurnOnOffLight extends Component {

  getOptions = async () => {

    try {

      const devices = await this.props.httpClient.get('/api/v1/device', {

        device_feature_category: 'light',

        device_feature_type: 'binary'

      });

Is this possible, or should I do it differently?
And most importantly, what do you think, leave two separate actions or combine them?

Hi @link39! I’ve made the topic public so everyone can follow the progress :slight_smile: (let’s avoid PMs please!)

Did you manage to get the Xiaomi switches working? Awesome! I actually have a user right now who wanted this compatibility :slight_smile:

Does it work outside of scenes as well?

What exactly are these devices? Connected plugs coupled with a wall switch?

Because in your case, yes, they are light bulbs, but for someone else, it could be a toaster, a coffee maker, or a pool…

If that’s the case, I think we can factor the code but keep a separate card.

Yes, it does exactly the same thing, but for the user, it needs to be clear and logical.

You can put the device category in the props of the « TurnOnOffLight » component, and thus create a card « Turn On the Switch » and « Turn Off the Switch » which are just based on the same Preact component.

What do you think? :slight_smile:

Thanks for your work!

I haven’t changed anything, it’s already compatible → Amazon.fr
In my example, it serves as a trigger. On a « single press », the value is 1.

Yes, I agree, I might have expressed myself poorly. Of course, a connected outlet or a wall switch (like a Fibaro switch / Xiaomi switch and co) is not just for turning on lamps :smiley: What I suggested was having an action (card) named: « Turn on light or switch ». In this, both « light » and « device » types would appear.

If we don’t want to combine these two types of devices in the same card, I think my code is quite clean and I can make a PR as is.

Here is the current rendering:

Oh ok I didn’t understand!

The Xiaomi serves as a trigger, I got that.

However: what do you control? A plug from which brand? What technology? Your « Turn On the Switchs » controls what?

Zwave control:

  • Fibaro FGS213
  • Fibaro Wall plug
  • Neo connected outlet

Ok, I’m excited about a PR with the two new actions « Turn on/off the Switch »! :slight_smile:

@link39 I saw on the forum that @jean_bruder had the same issue as you, but with Sonoff!

So I wonder in his case what we can do… Should we create a 3rd type of card, or should we create something more generic?

The Sonoff devices can also be seen as switches, I think. The « Turn on the switches » card should therefore control them and thus the lights (or other objects) connected to them.

Here is the branch where I made the modifications if you want to test and confirm that it meets the needs for the Sonoff devices:

Later, for easier user experience and to lessen the interface overload, I think having a single card « Turn on light or switch » would be better. Because later there will surely be other actions:

  • Change brightness (switch dimmer / light)
  • Change the color of a (light)
  • Change the temperature (thermostat)

Great! Whenever you’re ready for the PR :wink:

Well, I disagree! :stuck_out_tongue:

The « Turn On the lights » card will be able to specialize and offer, in addition to turning on the lights, turning them on with a specific color.

Whereas the « Turn On the Switches » card will remain quite simple

Oh yes but if you don’t say everything too :joy:

Actually, I misunderstood, here this development only concerns the scenes, no relation with Xiaomi!

No one is working on the support of Xiaomi switch switches at the moment.

I’ve created a task on GitHub to keep an eye on this development →

I’d like you to post the exact references of the hardware you’re trying to control on the issue.

After that, as you can see, it’s the 57th pending task ^^ There’s a lot of work!

There is a pending PR →

https://github.com/GladysAssistant/Gladys/pull/670

I finished the work on the PR this morning, it’s merged on master. The feature will likely go out in the beta as of this afternoon :slight_smile:

@atrixe144 The latest version of Gladys 4 now allows you to manage switches in scenarios. Your instance will update automatically. To check that you are on the latest version, you can verify in your Gladys dashboard under « /dashboard/settings/system » that you are on version:

You can already do it normally.

You need to make a « Get Last State » block.

Then a « Continue Only If » block.

Thanks Pierre Gilles for finishing this feature. Sorry, very little time at the moment.