• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
action: switch
#1
Please post anything you want to ask or tell about the switch action in this thread.
 
Reply
#2
Hi!

Is there any way to use a 433MHz remote to control the pilight event?
What I want to realize is to use an unused remote controll (with 3x ON/OFF) to switch between different light moods.

In example if I press the "A-ON" button the remote switches A, D and E should switch on and B and C should switch off. And if I press "A-OFF" every light should switch off but for A.

The idea behind this is to switch between moods like "normal", "movie", "party", "romantic" and so on, just by pressing one button.
 
Reply
#3
If I understood you correctly: yes that it possible.

First, as an example I assume you already have the remote switches defined as devices in pilight. As an example I will use devicenames remoteswitchA, remoteswitchB, remoteswitchC, remoteswitchD and remoteswitchE.

Second, create new switch devices for A-ON/OFF,B-ON/OFF and C ON/FF. Set protocol, unit and id according to the information you get with pilight-receive. Example:

Code:
[...]
    "devices": {
        "moodswitchA": {
            "protocol": [ "kaku_switch" ],
            "id": [{
                "id": 123455,
                "unit": 1
            }],
            "state": "off"
        },
        "moodswitchB": {
            "protocol": [ "kaku_switch" ],
            "id": [{
                "id": 123456,
                "unit": 1
            }],
            "state": "off"
        },
       "moodswitchC": {
            "protocol": [ "kaku_switch" ],
            "id": [{
                "id": 123457,
                "unit": 1
            }],
            "state": "off"
        }
    },
[...]

Third, create the rules to map moodswitch actions to remoteswitch actions.

Code:
[...]

"rules": {
      "moviemoodswitcheson": {
          "rule": "IF moodswitchA.state IS on THEN switch DEVICE remoteswitchA AND remoteswitchD AND remoteswitchE TO on",
          "active": 1
      },
      "moviemoodswitchesoff": {
          "rule": "IF moodswitchA.state IS on THEN switch DEVICE remoteswitchB AND remoteswitchC TO off",
          "active": 1
      }
  },
[...]

The example above will enable the move mood, the rest of the moods should be simple copies and some adjustments. The example could be enhanced, but this should be a decent first start.
 
Reply
#4
Thank you very much!

But this only works via the web gui. I can define a "movie" control for a "moods" tab like

Code:
"devices": {
                "moodswitchMovie": {
                        "protocol": [ "elro_800_switch" ],
                        "id": [{
                                "systemcode": 26,
                                "unitcode": 1
                        }],
                        "state": "off"
                }
}

[...]

"rules": {
                "moviemoodswitcheson": {
                        "rule": "IF moodswitchMovie.state IS on THEN switch DEVICE A1 AND elro01100C AND A2 TO on",
                        "active": 1
                }
}

[...]

"gui": {
                "moodswitchMovie": {
                        "name": "Movies",
                        "group": [ "Moods" ],
                        "media": [ "all" ]
                }
}

That works great if I trigger the gui switch! But how can I react on "origin: receiver" events, too? I'd like to use the hardware remote control to switch between the defined rules. Something like:

Code:
"rule": "IF moodswitchMovie.origin IS receiver AND moodswitchMovie.state IS on THEN switch DEVICE A1 AND elro01100C AND A2 TO on",
"active": 1

Or did I miss something?
Or is it beacuse pilight-receive does recognise the wrong protocol?

Code:
[Mar 01 18:10:55:391792] pilight-daemon: DEBUG: broadcasted: {"message":{"id":769962,"all":1,"state":"on"},"origin":"receiver","protocol":"cleverwatts","uuid":"0000-00-00-98-e34879","repeats":4}

pilight-receive sais:

Code:
{
        "message": {
                "id": 769962,
                "all": 1,
                "state": "off"
        },
        "origin": "receiver",
        "protocol": "cleverwatts",
        "uuid": "0000-00-00-98-e34879",
        "repeats": 1
}
{
        "message": {
                "id": 769962,
                "all": 1,
                "state": "off"
        },
        "origin": "receiver",
        "protocol": "cleverwatts",
        "uuid": "0000-00-00-98-e34879",
        "repeats": 2
}
{
        "message": {
                "id": "F3",
                "unit": 30,
                "state": "on"
        },
        "origin": "receiver",
        "protocol": "clarus_switch",
        "uuid": "0000-00-00-98-e34879",
        "repeats": 1
}
{
        "message": {
                "id": "F0",
                "unit": 30,
                "state": "on"
        },
        "origin": "receiver",
        "protocol": "rev2_switch",
        "uuid": "0000-00-00-98-e34879",
        "repeats": 1
}

instead of

Code:
"message": {
                "id": "26",
                "unit": 21,
                "state": "on"
        },
        "origin": "receiver",
        "protocol": "elro_800_switch",
        "repeats": 1
}
 
Reply
#5
The origin should not matter, just make sure the pilight is receiving the correct protocol.
 
Reply
#6
Hi,

I just updated to the pilight 6.0 and setup everything I need and it works.
Now I want to test with the events, but once I put in some rule, I never get pilight to start due to this error: "pilight-daemon: ERROR: config is not in a valid json format"

If I change:
Code:
"rules": {},

to

Code:
"rules": {
            "allon": {
                "rule": "IF (alles.state IS on) THEN switch DEVICE (vloerlamp AND wandlamp AND tafellamp1 AND tafellamp2) TO on",
                "active": 1
                },
            "alloff": {
                "rule": "IF (alles.state IS off) THEN switch DEVICE (vloerlamp AND wandlamp AND tafellamp1 AND tafellamp2) TO off",
                "active": 1            
                }
            },
Then I cannot start pilight anymore.

I stopped the service prior to changing and saving the config.json ofcourse.
Also I checked my json code with an online checker (missing parentheses and commas and such) but my code is valid.

I really would like to use these 'rules', did I miss a setting somewhere?
 
Reply
#7
Please post your full config.json
 
Reply
#8
Big Grin 
EDIT: got it working, code below.
Not sure what is different, but this works.

Code:
{
    "devices": {
        "alles": {
            "protocol": [ "generic_switch" ],
            "id": [{
                "id": 100
            }],
            "state": "on"
        },
        "vloerlamp": {
            "protocol": [ "elro_800_switch" ],
            "id": [{
                "systemcode": 21,
                "unitcode": 1
            }],
            "state": "on"
        },
        "wandlamp": {
            "protocol": [ "elro_800_switch" ],
            "id": [{
                "systemcode": 21,
                "unitcode": 2
            }],
            "state": "on"
        },
        "tafellamp1": {
            "protocol": [ "elro_800_switch" ],
            "id": [{
                "systemcode": 21,
                "unitcode": 4
            }],
            "state": "on"
        },
        "tafellamp2": {
            "protocol": [ "impuls" ],
            "id": [{
                "systemcode": 15,
                "programcode": 2
            }],
            "state": "on"
        }
    },
    "rules": {
        "Alles_Aan": {
            "rule": "IF alles.state IS on THEN switch DEVICE vloerlamp AND wandlamp AND tafellamp1 AND tafellamp2 TO on",
            "active": 1
        },
        "Alles_Uit": {
            "rule": "IF alles.state IS off THEN switch DEVICE vloerlamp AND wandlamp AND tafellamp1 AND tafellamp2 TO off",
            "active": 1
        }
    },
    "gui": {
        "alles": {
            "name": "Alle Lampen",
            "group": [ "Alle Lampen" ]
        },
        "vloerlamp": {
            "name": "Vloerlamp",
            "group": [ "Huiskamer" ]
        },
        "wandlamp": {
            "name": "Wandlamp",
            "group": [ "Huiskamer" ]
        },
        "tafellamp1": {
            "name": "Tafellamp bijzettafel",
            "group": [ "Huiskamer" ]
        },
        "tafellamp2": {
            "name": "Tafellamp TV-kast",
            "group": [ "Huiskamer" ]
        }
    },
    "settings": {
        "log-level": 4,
        "pid-file": "/var/run/pilight.pid",
        "log-file": "/var/log/pilight.log",
        "port": 5000,
        "send-repeats": 10,
        "receive-repeats": 1,
        "webserver-enable": 1,
        "webserver-root": "/usr/local/share/pilight/",
        "webserver-port": 5001,
        "webserver-cache": 1,
        "firmware-update": 0
    },
    "hardware": {
        "433gpio": {
            "sender": 15,
            "receiver": -1
        }
    },
    "registry": {
        "webgui": {
            "tabs": 1
        },
        "pilight": {
            "version": {
                "current": "6.0"
            }
        }
    }
}
 
Reply
#9
I am running openweathermap-protocol and now i would like to switch some light depending on sunset-time.
Is there a chance to split the sunset-time of openweathermap-protocol into hour and minute?
I think about someting like this...
Code:
"IF outdoor.sunset.hour == datetime.hour AND outdoor.sunset.minute == datetime.minute AND datetime.second == 00 AND switch1.state IS off THEN switch DEVICE switch1 TO on"
 
Reply
#10
There is an even simpler solution available already in the third party section of the wiki in Time Math: http://wiki.pilight.org/doku.php/3rdpartymodules.
I think the newdatetime operator will suit your needs.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  _VARSTORE_ set action fourty2 1 1,019 05-19-2019, 09:07 PM
Last Post: curlymo
  skipping overridden action switch do1eh 2 680 01-19-2019, 05:25 PM
Last Post: do1eh
  http action Niek 21 4,632 08-12-2018, 11:44 AM
Last Post: rorie
  Can't switch Relay device by rules: Error switch.lua:77 wobbi 6 1,070 07-31-2018, 06:25 AM
Last Post: curlymo
  Send on command when switch is already "on" joshovki 1 624 01-28-2018, 11:27 PM
Last Post: curlymo
  action: Pushbullet bazb 24 12,081 01-04-2018, 08:38 PM
Last Post: curlymo
  action: pushover Niek 36 18,304 12-03-2017, 11:13 AM
Last Post: Alex
  Problem with a Rule for a One Button Switch martin-dj 1 1,339 03-06-2017, 12:01 PM
Last Post: pilino1234
  duration switch protocol creamers 6 2,509 01-10-2017, 10:04 PM
Last Post: wo_rasp
  action: file Niek 14 4,285 06-23-2016, 04:02 PM
Last Post: Niek

Forum Jump:


Browsing: 1 Guest(s)