Moving to OpenHAB to get Google Home support for free?

Alexa, Google Home and Siri

Moderator: leecollings

Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

Domoticz is mutch more user friendly to setup. Everything is setup via web interface.
On openhab you setup most of the system by editing configuration files. I think they try to make it more user friendly. Like with the mqtt binding that is now updated to be setup via web interface. I still use the old one as I don't know how to merge my setup to the new version.

However I think you find lot of good info on openhab website.
https://www.openhab.org/docs/
febalci
Posts: 331
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by febalci »

I for one came from openhab world to domoticz. Openhab tried to move from config files to user friendly type, but as i was moving out it was neither of both worlds. I had to create some parts as config files and some others (since config files were not supporting it) created in paper ui. And after you add in zwave, it was completely a mess. The reason why i moved on to domoticz was simplicity, uniformity and of course python plugin files. And i am happier ever. This is just my personal opinion but i am just sayin...
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by ricorico94 »

Hi,

I'm very interested in this approach and tried it, but I can't make it work..
I installed openhabian on a separate PI. I installed MQTT on that PI as well and configured Domoticz to update that MQTT broker. That seems working, because when I use a tool like mqtt-spy-1.0.0.jar I can indeed view domoticz messages coming out.
I tried to follow the guidelines from this thread, but I can't see anything in Openhab.. So I probably made a mistake somewhere.
First, I installed openhab2.4, the latest version.. I initially installed the new MQTT binding. As I couldn't get any success with the procedure, I uinstalled (using PaperUI) that binding and used PaperUI again to install the "MQTT Binindg 1.x"
-> now, I get an error in Openhab, stating that the Openhab Thing "MQTT Broker" is "uninitialized" (even after having rebooted the PI) : Is it because I only used the PaperUI to install the binding? Do I need to create a configuration file manually ? In a openhab tutorial for MQTT 1.x, I could read that a file mqtt.cfg has to be created or modified manually in /services folder : is it something to be done though not described in the step by step guide of this thread ?
I read in an openhab doculentation (https://www.openhab.org/addons/bindings/mqtt.generic/) that some files in .things are required, like the demo1.things described in that page. Is it something to be done and is it not overlapping with the .items definitions described by Ankan ?

-> Another question is how to understand that statement from Ankan:
The rule only works if you use the name format idx123 where 123 is your device idx number in dometicz.
Where should I setup "idx123" ? Is it Domoticz, but then we lose a full description ? Or in openhabian, but then I don't understand where to define that.. Or are they created and named automatically thanks to the .items file suggested by Ankan ? The first item in the file from Ankan starts with "idx123", but not the second line (for outdoortemperature), so I feel lost.

-> also, as I like understanding (at least trying), could someone explain to me the syntax of the jsonpath:
JSONPATH($.svalue1):(?s).*idx\".?.?.?124,.*
I understand it looks for svalue1, but I don't understand the remaining structure (the ?s, and the multiple dots ?.?.?124 ). I tried to look at jsonpath syntax, but could not find such example

I'd highly appreciate if anyone could help me. This is driving me nuts ! :shock:

br,
Ricorico94
Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

Hi!

You are right. You have to change that mqtt.cfg file to get mqtt 1.x client to work. Even if mqtt server is on same machine openhab have no information about that. That is why you have to setup that mqtt binding.

The name format does only affect the name on openhab. And only the name (identity). The displayed name can be different.
Idx123 is a switch that you want to control from openhab. That is why the name is so important so the outgoing mqtt message to domoticz will be right.
The second device is a temperature sensor on domoticz that you want to show in openhab, and that's it. You can't charge temperature. It's a one way device, so the name is not important. Only the incoming mqtt message filter in the end of that row is important wher you tell it to listen to messages from idx124 for temperature.

That expression is a regex expression to filter messages with only that idx.

Explanation from regex101.com
(?s) match the remainder of the pattern with the following effective flags: gms
s modifier: single line. Dot matches newline characters
.* matches any character
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
idx matches the characters idx literally (case sensitive)
\" matches the character " literally (case sensitive)
.? matches any character
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
.? matches any character
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
.? matches any character
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
124, matches the characters 124, literally (case sensitive)
.* matches any character
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by ricorico94 »

Hi Ankan,

Thanks a lot for your explanations. At least, now, I understand the structure of your MQTT action with the JSONpath and the regex to filter !

After 4 hours of investigation (tests, retests, reboots, readings and almost despair), I finally made it work. I've not yet tried the steps with the Cloud, etc., but at least I get reflected devices between domoticz and openhab...
What helped me, if it can help others...
- read the tutorial https://community.openhab.org/t/mqtt-bi ... -101/33958 including the steps 6 and 7 to test.. and of course look at Ankan's message...
- then avoid the stupid but huge mistake I made: in mqtt.cfg file, I used the default name of broker, ie:

Code: Select all

broker.url=tcp://localhost:1883
broker.user=openhabian
broker.pwd=abcdefg
but in Ankan's examples, he uses another name:

Code: Select all

mqttBroker.url=tcp://localhost:1883
mqttBroker.user=openhabian
mqttBroker.pwd=abcdefg
as long as I kept the default, the domoticz devices were not detected by openhab.. and once I made the change, it worked..
And I realized that Ankan had briefly mentioned that fact, but I had not understood the importance of that short statement..
The weird thing is that the test switch created as per tutorial mentioned above is still working despite its definition in items is:

Code: Select all

Switch MQTT_Test "Testing..." { mqtt="<[broker:testing/mqtt/topic:state:default], >[broker:testing/mqtt/back-topic:command:*:default]" }
thus using "broker" name instead of "mqttBroker".. I don't know why this one is still working.

So, Ankan, thanks a lot !!! I hope I'll face less issues with the next steps. :roll: I must admit that I find openHab far more obscure and complex than Domoticz.

As a recap for newcomers to openhab and MQTT like me, here are a couple links I found interesting to duplicate the trick from Ankan:
- tutorial on installation of openhab : https://www.openhab.org/docs/tutorial/1sttimesetup.html
- tutorial on MQQT bindings 1.x : https://www.openhab.org/addons/bindings/mqtt1/ for the explanation on filtering trick used by Ankan
- tutorial on installation of MQTT Binding which must be followed even in OPenhab 2.x: https://community.openhab.org/t/mqtt-bi ... -101/33958
- comparison MQTT binding 1 and 2: https://www.openhab.org/blog/2018-12-16 ... cture.html (if I ever have the time to try transposing to Binding 2.x...)
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Gravityz »

Hi Arkan,

i am almost finished with the domoticz to Openhab connectivity.
all light switches work (through HAbridge)

MQTT seems to be working between Openhab, domoticz and a windows mqtt client

eg made a test switch in openhab .items and . sitemaps
if i flip the switch i see the message in mqtt

if i subsibe to domoticz/out in the windows client i also see all the domoticz mqtt messages appear.

i can however not receive the temperature sensor from domoticz in openhab.

The temp sensor has IDX 279
this is what is being send out

Code: Select all

domoticz/out/{
   "Battery" : 100,
   "RSSI" : 6,
   "description" : "",
   "dtype" : "Temp",
   "id" : "23041",
   "idx" : 279,
   "name" : "Tuin",
   "nvalue" : 0,
   "stype" : "TFA 30.3133",
   "svalue1" : "16.7",
   "unit" : 1
}

in the demo.item file i have put this

Code: Select all

Number Tuin "Temperature [%.1f]" <temperature> ["CurrentTemperature"] {mqtt="<[mosquitto:domoticz/out:state:JSONPATH($.svalue1):(?s).*idx\".?.?.?279,.*]"}
i get this in the log

Code: Select all

2019-06-20 07:35:05.288 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'Tuin'
2019-06-20 07:35:12.522 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH 
2019-06-20 07:35:12.524 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH 
2019-06-20 07:35:12.565 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH 
do you perhaps know what is going wrong.



Ankan wrote: Thursday 06 December 2018 22:21 Okey, it's up and running. Let's see if it's possible to make it even better.

*
So this is how I solved it and it works for me. I would prefer to not enter idx number two times on same row in items-file, but I couldn't solve it any other way.

Items:

Code: Select all

Switch idx123 "Outdoorlamp" (gLight) [ "Lighting" ] {mqtt="<[mqttBroker:domoticz/out:state:JS(get_state.js):(?s).*idx\".?.?.?123,.*]"}
Number Outdoor_Temperature "Temperature [%.1f]" <temperature> ["CurrentTemperature"] {mqtt="<[mqttBroker:domoticz/out:state:JSONPATH($.svalue1):(?s).*idx\".?.?.?124,.*]"}
123 and 124 is device idx in Domoticz. mqttBroker is what I configured the mqtt-connection to be called in mqtt binding.
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Gravityz »

solved it myself (what else is new)
Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

Gravityz wrote: Saturday 22 June 2019 14:10 solved it myself (what else is new)
Nice to hear. Please share your solution for the future.
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Gravityz »

there is a typ0 in the string you posted

you did put a , behind the idx id and that is wrong.
when i deleted the , it is working

i however switched to MQTT 2.0 so i do not need the items, sitemaps anymore.


Code: Select all

Number Tuin "Temperature [%.1f]" <temperature> ["CurrentTemperature"] {mqtt="<[mosquitto:domoticz/out:state:JSONPATH($.svalue1):(?s).*idx\".?.?.?279.*]"}
Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

I checked my items file and I have that , after the idx id so I don't think it's a typ0.

Typical MQTT data from domoticz/out on my MQTT server looks like this:

Code: Select all

{
   "Battery" : 100,
   "RSSI" : 12,
   "description" : "",
   "dtype" : "Temp",
   "id" : "12345",
   "idx" : 1,
   "name" : "AlectoV3",
   "nvalue" : 0,
   "stype" : "LaCrosse TX3",
   "svalue1" : "-20.5",
   "unit" : 56
}
... but I guess it will work without that , also.

Gravityz, it would be very nice of you if you could write some instructions of how to migrate to MQTT 2.0.
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Gravityz »

i am working on it.
it took some time to figur things out but at the moment i have all the temperature sensors from domoticz as things and items in Openhab.

i am trying to document it because openhab is not the easiest to work with.

eg when you create things with certain options and you edit it egain you do not see all the options so it is hard to find out what you did the first time.

i am also trying to figur out how i can sync the status from domoticz to openhab.
openhab-habridge-domoticz is no problem but when you flip a switch in domoticz it does not flip in openhab.

i think MQTT can play a part in this as well
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by ricorico94 »

@Gravityz : could you progress on how o use MQTT v2 ?

Also, I had to restart my whole systems a few days ago, and since then, I can't ask temperatures anymore.. Openhab is updated properly by domoticz via MQTT (v1) (according to its log), but my google Home mini doesn't want to find these temperatures anymore. Weirdly, I can still order siwtching on/off lights.

I saw that openhab recently updated their google assistant connector and I saw that now thermostats must be used intead of using directly Currenttemperature flag.. Maybe that's the reason.
Do you face same issue ? Could you advsie how to modify the .items file for using these THermostat groups ?

br,
Ricorico94
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Gravityz »

sure.
i documented everything but since there were no replies in this thread i figured nobody was waiting for this
regarding your second question.
indeed you need to tag the temperature as a thermostat . humidity is still CurrentHumidity but you need to group both the temperature(which is the thermostat"and the humidity together.

i also found out that you can do the tagging with the rest api but you can also do it from within the items file

this is in my items file(i think this still works without renaming CurrentTemperature)

Code: Select all

Group    gThermostaat                       "Thermostaat"                           <temperature>                          [ "Thermostat" ]
String   Woonkamer_mode                     "Heating/Cooling Mode"                                     (gThermostaat)      [ "homekit:TargetHeatingCoolingMode" ]
Number   Temperatuur_Woonkamer              "Temperatuur woonkamer [%.1f °C]"       <temperature>      (gThermostaat)      [ "CurrentTemperature" ]              {mqtt="<[mosquitto:domoticz/out/woonkamer/temperatuur:state:JSONPATH($.svalue1)]"}
Number   Vochtigheid_Woonkamer              "Lucht vochtigheid woonkamer [%s %%]"    <Humidity>        (gThermostaat)      [ "CurrentHumidity" ]                 {mqtt="<[mosquitto:domoticz/out/woonkamer/temperatuur:state:JSONPATH($.svalue2)]"}
Number   Woonkamer_Setpoint                 "Temperatuur [%.1f °C]"                 <temperature>      (gThermostaat)      [ "homekit:TargetTemperature" ]
in case you are dutch.
from google asistant you can ask for the temperature in a room and also humidity.
some idiot translated it the wrong way so the only way to get the humidity in dutch is to ask "wat is de vochtigheid in de woonkamer?)

humidity translates to dutch as "luchtvochtigheid" but google assistant does not understands this


regarding MQTT.
MQTT 1.x works without problems but you can not make things and items with this so you can not see them in the openhab user interface.
after i figured out how to do this with MQTT 2.x is also started using the openhab app on my iphone which only works with the items and sitemaps so i went back to that.

here is the complete manual i wrote. nearly idiotproof but in case things do not work out please google before asking(that is how i finally figured out things)

please send me an pm with your email address and i will send it to you.
it is to big to upload in this thread(it won't let me)

also let me know if you use domoticz to send out the temperature readings
if you do you need to change something there as well
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by ricorico94 »

Thanks a lot Gravityz !
One thing I wonder is whether or not I must only have one "currenttemperature" per Thermostat group, or if I can create a single one for all my rooms (I have several sensors in the house, almost on per room and if I could avoid creating one group per room, it would be easier to read).
I'll have to try anyway, I guess..

Not sure what you mean by " let me know if you use domoticz to send out the temperature readings" : I do capture temperatures in domoticz, send them to Openhab via MQTT then ask google home mini to announce them thanks to the MQTT trick. Was it your question ?

br,
Ricorico94
Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

Gravityz, it would be great if you could manage to put your documentation here. Maybe just copy and paste?
Else upload it to a server that you link from here.

I would love to read your documentation also, but instead of asking for it by PM with my email address I think it's better if its possible to make it public here instead.
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by ricorico94 »

HI again,

I modified my .items and indeed I think we have to use a distinct Thermostat group for each room, otherwise temperatures would not be attached to ad hoc room by Google Home. So I created 1 thermostat group for each room and then one temperature sensor in each thermostat..
It seems working.
One note though, as I had forgotten the process: once uploaded the new .items file, we have to ask google to sync devices "OK google, sync my devices" and then we have to wait for domoticz to update the temperature of the sensor (otherwise google home will not find the value).

I wanted to try adding a device related to my blinds, but I couldn't succeed. Now it seems a category "Rollershutter" exists, so I added:

Code: Select all

Rollershutter idx999 "volets du salon" (gBlinds) ["Blinds"] {mqtt="<[mqttBroker:domoticz/out:state:JS(get_state.js):(?s).*idx\".?.?.?999,.*]"}
but then commands did not succeed.
I tried to modify the mqtt.rules files as follows, to create a rule for the gBlinds group but it failed as well:

Code: Select all

rule "Send MQTT message on Light command"
when
	Member of gLight received command
then
	var idxStartPos = triggeringItem.name.indexOf("idx") + 3
	var idxStopPos = triggeringItem.name.length()
	var  myString = ""

	if (triggeringItem.state.toString() == "ON" || triggeringItem.state.toString() == "OFF")
	{
		var cmd = triggeringItem.state.toString().toLowerCase.toFirstUpper()
		// {"command": "switchlight", "idx": 2450, "switchcmd": "On" }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"' + cmd + '\"}'
	}
	else
	{
		// {"command": "switchlight", "idx": 2450, "switchcmd": "Set Level", "level": 100 }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"Set Level\", \"level\": ' + triggeringItem.state.toString() + '}'
	}

	publish("mqttBroker", "domoticz/in", myString)
end

rule "Send MQTT message on Blinds command"
when
	Member of gBlinds received command
then
	var idxStartPos = triggeringItem.name.indexOf("idx") + 3
	var idxStopPos = triggeringItem.name.length()
	var  myString = ""

	if (triggeringItem.state.toString() == "UP" || triggeringItem.state.toString() == "DOWN")
	{
		if (triggeringItem.state.toString() == "UP")
		{ var cmd = "On" }
		else
		{ var cmd = "Off"}
		
		//var cmd = triggeringItem.state.toString().toLowerCase.toFirstUpper()
		// {"command": "switchlight", "idx": 2450, "switchcmd": "On" }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"' + cmd + '\"}'
	}
	else
	{
		// {"command": "switchlight", "idx": 2450, "switchcmd": "Set Level", "level": 100 }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"Set Level\", \"level\": ' + triggeringItem.state.toString() + '}'
	}

	publish("mqttBroker", "domoticz/in", myString)
end
If I ask to open, it seems working. If I ask to close the blinds, then google seems ok, but domoticz doesn't trigger.
In Domoticz, I see in logs:

Code: Select all

 MQTT: Topic: domoticz/in, Message: {"command": "switchlight", "idx": 999, "switchcmd": "Set Level", "level": 100}
 Error: MQTT: Error sending switch command!
Any idea of what I should do ?

ricorico94
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Gravityz »

copy/paste does not work

i would love to share it but this site MUST make it possible for me to upload a simple 1MB file

github works really easy either with copy/paste or with upload file but this site is absolutely not user friendly.

I have asked the administrator to raise the limit.

Ankan wrote: Wednesday 27 November 2019 22:17 Gravityz, it would be great if you could manage to put your documentation here. Maybe just copy and paste?
Else upload it to a server that you link from here.

I would love to read your documentation also, but instead of asking for it by PM with my email address I think it's better if its possible to make it public here instead.
Ankan
Posts: 48
Joined: Thursday 09 November 2017 20:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Ankan »

Upload it somewhere else and put a link here would work.
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Gravityz »

not sure what is going wrong because i do not have shutters.

you use this command
{"command": "switchlight", "idx": 999, "switchcmd": "Set Level", "level": 100}

this is from the manual(has an extra space at the end)
{"command": "switchlight", "idx": 245, "switchcmd": "Set Level", "level": 100 }


maybee that space is the solution, if know i would not know




ricorico94 wrote: Wednesday 27 November 2019 23:42 HI again,

I modified my .items and indeed I think we have to use a distinct Thermostat group for each room, otherwise temperatures would not be attached to ad hoc room by Google Home. So I created 1 thermostat group for each room and then one temperature sensor in each thermostat..
It seems working.
One note though, as I had forgotten the process: once uploaded the new .items file, we have to ask google to sync devices "OK google, sync my devices" and then we have to wait for domoticz to update the temperature of the sensor (otherwise google home will not find the value).

I wanted to try adding a device related to my blinds, but I couldn't succeed. Now it seems a category "Rollershutter" exists, so I added:

Code: Select all

Rollershutter idx999 "volets du salon" (gBlinds) ["Blinds"] {mqtt="<[mqttBroker:domoticz/out:state:JS(get_state.js):(?s).*idx\".?.?.?999,.*]"}
but then commands did not succeed.
I tried to modify the mqtt.rules files as follows, to create a rule for the gBlinds group but it failed as well:

Code: Select all

rule "Send MQTT message on Light command"
when
	Member of gLight received command
then
	var idxStartPos = triggeringItem.name.indexOf("idx") + 3
	var idxStopPos = triggeringItem.name.length()
	var  myString = ""

	if (triggeringItem.state.toString() == "ON" || triggeringItem.state.toString() == "OFF")
	{
		var cmd = triggeringItem.state.toString().toLowerCase.toFirstUpper()
		// {"command": "switchlight", "idx": 2450, "switchcmd": "On" }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"' + cmd + '\"}'
	}
	else
	{
		// {"command": "switchlight", "idx": 2450, "switchcmd": "Set Level", "level": 100 }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"Set Level\", \"level\": ' + triggeringItem.state.toString() + '}'
	}

	publish("mqttBroker", "domoticz/in", myString)
end

rule "Send MQTT message on Blinds command"
when
	Member of gBlinds received command
then
	var idxStartPos = triggeringItem.name.indexOf("idx") + 3
	var idxStopPos = triggeringItem.name.length()
	var  myString = ""

	if (triggeringItem.state.toString() == "UP" || triggeringItem.state.toString() == "DOWN")
	{
		if (triggeringItem.state.toString() == "UP")
		{ var cmd = "On" }
		else
		{ var cmd = "Off"}
		
		//var cmd = triggeringItem.state.toString().toLowerCase.toFirstUpper()
		// {"command": "switchlight", "idx": 2450, "switchcmd": "On" }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"' + cmd + '\"}'
	}
	else
	{
		// {"command": "switchlight", "idx": 2450, "switchcmd": "Set Level", "level": 100 }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"Set Level\", \"level\": ' + triggeringItem.state.toString() + '}'
	}

	publish("mqttBroker", "domoticz/in", myString)
end
If I ask to open, it seems working. If I ask to close the blinds, then google seems ok, but domoticz doesn't trigger.
In Domoticz, I see in logs:

Code: Select all

 MQTT: Topic: domoticz/in, Message: {"command": "switchlight", "idx": 999, "switchcmd": "Set Level", "level": 100}
 Error: MQTT: Error sending switch command!
Any idea of what I should do ?

ricorico94
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Moving to OpenHAB to get Google Home support for free?

Post by Gravityz »

@Ankan.
send me pm so i can send you the documentation.

@ricorico94
let me know if you received it

still no feedback regarding raising the 1MB limit on this site
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests