Using the "Selector switch" in Domoticz (tutorial)
-
Domoticz features a special switch type named "Selector switch" . This switch type can serve many MySensors purposes. In this walk through it is used for selecting different light patterns in my Wall mounted 'mood light'.
A "button set"
or "select menu"
Essentially it is (or can be) a switch which controls another device. In this case I use it to control a dimmer. Let's start.
- Create a virtual hardware device (if you have not already done so before)
- Create a new "Virtual Sensor" with type "Selector Switch" by pressing the "Create Virtual Sensors" button.
you can also use the "Manual Light/Switch" button in the "Switches" tab.
This will create a new Virtual selector switch.
I will use this to control a dimmer device which output is used to set the light patterns in the mood light
- In the devices tab find the "Dimmer you want the Selector attached to (in this case RGB Wall Pattern W 62" with index 971
"Edit" the newly created Selector switch and for each of the selector states attach a command to be executed.
The commands here can be pretty much anything but here I used the Domoticz JSON command to set the Dimmer to one of the 16 possible states (Yes, a dimmer can only asume 16 states). You need to put your own domoticz URL/IP and port number in there. "Idx" is the dimmer device index from the previous step.
A maximum of 10 switch values can be assigned
don't forget to save
I deliberately did not set "level 1" , because this translates to "0" and is associated with the off state in my case (room light)for the copycats (don't forget to include your own values):
http://192.168.2.110:8080/json.htm?type=command¶m=switchlight&idx=971&switchcmd=Set%20Level&level=0
That's it. Now when you press a selector button it switches the dimmer value.
In your sketch you can translate the dimmer values to differenct actions. Have a look at the Wall light sketch for an example.
-
To make the tutorial complete, below the MySensors receive routine to handle the input ( @Reza )
// Incoming messages from MySensors // Template to demonstrate use of V_PERCENTAGE for Selector Switch in Domoticz void receive(const MyMessage &message) { int ID = message.sensor; int mySwitch = 0 ; Serial.print("Sensor: "); Serial.println(ID); switch (ID){ // If different sensors for this node case sensorID: // the number of the V_PERCENTAGE sensor to be controlled if (message.type == V_PERCENTAGE) { // Percentage indicates the pattern mySwitch = map(message.getInt(), 0, 100, 0, 15); // mapper dimmer values to Switch states 0..9 and wrap switch (mySwitch){ case 0: { } // whatever on switch action 0 break ; case 1: { } // whatever on switch action 1 break ; case 2: { } // whatever on switch action 2 break ; case 3: { } // whatever on switch action 3 break ; case 4: { } // whatever on switch action 4 break ; // etc. max switch actions in Domoticz = 10 } break ; } } }
-
@AWI
my friend , I'm embarrassed , answer in forum
i'am sorry .
so i upload this sketch in ir sensor :// Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_RF24_CHANNEL 0 #define MY_REPEATER_FEATURE #include <SPI.h> #include <MySensors.h> #include <IRLib.h> int RECV_PIN = 8; #define CHILD_1 3 // childId IRsend irsend; IRrecv irrecv(RECV_PIN); IRdecode decoder; //decode_results results; unsigned int Buffer[RAWBUF]; MyMessage msg(CHILD_1, V_VAR1); void setup() { irrecv.enableIRIn(); // Start the ir receiver decoder.UseExtnBuf(Buffer); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("IR Sensor", "1.0"); // Register a sensors to Use binary light for test purposes. present(CHILD_1, S_LIGHT); } void loop() { if (irrecv.GetResults(&decoder)) { irrecv.resume(); decoder.decode(); decoder.DumpResults(); char buffer[10]; sprintf(buffer, "%08lx", decoder.value); // Send ir result to gw send(msg.set(buffer)); } } void receive(const MyMessage &message) { int ID = message.sensor; int mySwitch = Serial.print("Sensor: "); Serial.println(ID); switch (ID){ // If different sensors for this node case sensorID: // the V_PERCENTAGE sensor to be controlled if (message.type == V_PERCENTAGE) { // Percentage indicates the pattern mySwitch = map(message.getInt(), 0, 100, 0, 15); // mapper dimmer values to Switch states 0..9 and wrap switch (mySwitch){ case 0: { } // whatever on switch action 0 break ; case 1: { } // whatever on switch action 1 break ; case 2: { } // whatever on switch action 2 break ; case 3: { } // whatever on switch action 3 break ; case 4: { } // whatever on switch action 4 break ; // etc. max switch actions in Domoticz = 10 } break ; } }
and in selector switch in Selector actions put this :
http://192.168.2.110:8080/json.htm?type=command¶m=switchlight&idx=971&switchcmd=Set Level&level=0so where write the ir codes ?
thank you
-
@Reza
I'm not going to spell it out for you, there needs to be something to investigate yourself... the comments are rather self explaining. So put your actions between the curly brackets..case 0: { } // whatever on switch action 0 break ;
-
@AWI
thank you , you are kind friend
-
Greetings!
So i have a ledstrip and i am using your sketch straight off.
I do not have a physical button connected, but the code for the button is still there.I have setup a Selector Switch in domoticz like in your example, but i doesnt work with the values 2,3,4 etc. the patterns doesnt start.
If i change it to http://192.168.1.30:8090/json.htm?type=command¶m=switchlight&idx=157&switchcmd=Set Level&level=25 i get the alarm blinking red and white.what are the values for each pattern in your "moodlight" sketch?
Or do i have to add something to the sketch for it to work?
-
I did the selector <> dimmer mapping in lua:
-- -- Heat pump mode selector <> dimmer mapping with lua -- commandArray = {} selectorName = 'Pumppu_Mode' selectorId = '332' -- needed for UpdateDevice dimmerName = 'Pumppu_ModeSW2' -- selector -> dimmer if(devicechanged[selectorName]) then iDimLevel = tonumber(otherdevices_svalues[selectorName]) if(iDimLevel < 60) then -- not needed anymore? commandArray[dimmerName]='Set Level '..iDimLevel end end -- dimmer-> selector. UpdateDevice is not triggering this script again if (devicechanged[dimmerName]) then if (devicechanged[dimmerName] == 'Off') then commandArray['UpdateDevice'] = selectorId..'|0|0' else iCurrentDimLevel = 0 if(otherdevices[dimmerName] == 'On') then -- can be "On" or something else iCurrentDimLevel = tonumber(otherdevices_svalues[dimmerName]) else iCurrentDimLevel = tonumber(string.match(otherdevices[dimmerName], "Set Level: (%d+) %%")) end commandArray['UpdateDevice'] = selectorId..'|'..iCurrentDimLevel..'|'..iCurrentDimLevel end end return commandArray```
-
Hello AWI , is it possible to post the hole example sketch ?