Switch MQTT controlers??
Moderators: grovkillen, Stuntteam, TD-er
Switch MQTT controlers??
Is there any way in rules to deactivate/activate MQTT controllers?
Here is what I want to do. Have a device setup with two SSID's to connect to. Depending on the SSID, I want to activate the MQTT-1 controller or the MQTT-2 controller. The MQTT-1 controller would be in my local network, but MQTT-2 would be BeeBotte for when the device was at a second location where it would connect to SSID2.
While I know I could use BeeBotte (remote MQTT) all the time, I want to setup a fallback like you can do with the SSID's.
Thanks in advance for any guidence (even it is 'nope')
Here is what I want to do. Have a device setup with two SSID's to connect to. Depending on the SSID, I want to activate the MQTT-1 controller or the MQTT-2 controller. The MQTT-1 controller would be in my local network, but MQTT-2 would be BeeBotte for when the device was at a second location where it would connect to SSID2.
While I know I could use BeeBotte (remote MQTT) all the time, I want to setup a fallback like you can do with the SSID's.
Thanks in advance for any guidence (even it is 'nope')
Re: Switch MQTT controlers??
I noticed that @TD-er recently added two new commands for the controllers. See ControllerDisable and ControllerEnable commands:
https://espeasy.readthedocs.io/en/lates ... mmand.html
For the record I have no experience with the new commands. Just passing on the info in case it helps your application.
- Thomas
https://espeasy.readthedocs.io/en/lates ... mmand.html
For the record I have no experience with the new commands. Just passing on the info in case it helps your application.
- Thomas
Re: Switch MQTT controlers??
SWEET!!! that works! now to see if I can check the SSID and set it.
Re: Switch MQTT controlers??
well I can get it to work using %ip4% since that is a value
so If I set my home network to assign the IP based on the device's MAC address the odds of getting that same octet on another network are about 1 in 254 which are pretty good odds it won't get the same octet!
Too bad there isn't a system variable to let you know if you are on the primary or fallback SSID (like 1 or 2)
UPDATE: Yup it works. If I leave the IP settings blank and have my router assign the IP address, with the rules above, I can turn of the controller I want!
Code: Select all
on System#Boot do
ControllerDisable,1
ControllerDisable,2
endon
on WiFi#Connected do
if %ip4% = 28 do
ControllerEnable,1
else
ControllerEnable,2
endif
endon
Too bad there isn't a system variable to let you know if you are on the primary or fallback SSID (like 1 or 2)
UPDATE: Yup it works. If I leave the IP settings blank and have my router assign the IP address, with the rules above, I can turn of the controller I want!
Last edited by dampa on 17 Mar 2020, 21:00, edited 2 times in total.
Re: Switch MQTT controlers??
Perhaps %bssid% (MAC) will allow you to detect which network is connected.
- Thomas
- Thomas
Re: Switch MQTT controlers??
If you have primary and secondary set, you also have different SSID's, and there is the %ssid% variable.
Also there is an event when you are connected to WiFi, so in that block you can compare the %ssid% value.
Only thing is that currently the string matching is a bit limited, but another recent addition is the substring stuff as described here: https://espeasy.readthedocs.io/en/lates ... terpreting
Also there is an event when you are connected to WiFi, so in that block you can compare the %ssid% value.
Only thing is that currently the string matching is a bit limited, but another recent addition is the substring stuff as described here: https://espeasy.readthedocs.io/en/lates ... terpreting
Re: Switch MQTT controlers??
Thomas, I don't think that would work since (if I understand it) in rules you can not do a compare to a string, and %bssid% is 50:C7:BF:78:4F:7B.
If you could use a string in a rule I could just use
but that doesn't work (I tried it)
But my idea in my previous post does work and will only fail if the other system assigns the same 4th octet in the IP address
If you could use a string in a rule I could just use
Code: Select all
if %ssid% = "My hidden SSID" do
But my idea in my previous post does work and will only fail if the other system assigns the same 4th octet in the IP address
Re: Switch MQTT controlers??
Understood. My idea was provided because it sounded like you wanted to harden your rules.But my idea in my previous post does work and will only fail if the other system assigns the same 4th octet in the IP address
String variables are new, so if this idea does not work then (as mentioned by TD-er) there is also a new substring parser. Theoretically it could be used to sample some digits in the %bssid% for use in your rules (that is to say, skip the colons). https://espeasy.readthedocs.io/en/lates ... #substringI don't think that would work since (if I understand it) in rules you can not do a compare to a string, and %bssid% is 50:C7:BF:78:4F:7B.
But unfortunately there seems to be a bug in substring. I just did a quick test and found that all digits after the first colon are ignored by the substring function. So this solution won't work at the moment.
But there is also a %mac_int% system var. This value is the last 24 bits of MAC address (as an integer) for use in your rules. I think this is a possible candidate for determining the online network.
BTW, the "do" keyword at the end of your "if" statement is not needed. The "do" is reserved for "on" rules.
- Thomas
Re: Switch MQTT controlers??
So that would work if the SSID had a number in it. Am I right that the rules will only work on string that are in fact numbers?TD-er wrote: ↑17 Mar 2020, 20:35 If you have primary and secondary set, you also have different SSID's, and there is the %ssid% variable.
Also there is an event when you are connected to WiFi, so in that block you can compare the %ssid% value.
Only thing is that currently the string matching is a bit limited, but another recent addition is the substring stuff as described here: https://espeasy.readthedocs.io/en/lates ... terpreting
Since my SSID is "Mines of Moria" it won't work, but if my SSID was "Mines of Moria 99" I could extract the 99 out with substring and then use that value.
the down side of doing that is I would have to change every device (and my wife's devices and my kids when they came to visit) to use the new SSID
For now I'll stick to using %ip4%, but it would be nice if there was a value (number) showing if I was using the primary or secondary SSID
Re: Switch MQTT controlers??
Yep in rules we now must turn the values to compare into numerical values.
There is a hex converter command, so BSSID can be turned into an integer value. But it does need some level of masochism to really like doing it like that.
If %ip4% (or another part of your subnet) does also work, please do use it.
Also the enable/disable task and controller commands are really new and I even fixed a bug in the -task variant of these commands.
So please let me know if you found something odd in using them.
There is a hex converter command, so BSSID can be turned into an integer value. But it does need some level of masochism to really like doing it like that.
If %ip4% (or another part of your subnet) does also work, please do use it.
Also the enable/disable task and controller commands are really new and I even fixed a bug in the -task variant of these commands.
So please let me know if you found something odd in using them.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 95 guests