MQTT LighBulbs/StripLED GoogleHome Item

Hi there,
I’m trying to configure a set of lightbulbs/stripleds with OH2 and Google Home.
The objects are Itead, SonOFF items, flashed with Espurna firmware.

My problem is that I can’t understand how to create the items for controlling colors, brightness etc.
I’m able to turn on/off the lights with my voice via the item config below:

Switch Test_Light "Luce test" [ "Lighting" ]
    { mqtt=">[broker:test/lightbulb/relay/0/set:command:ON:default],
            >[broker:test/lightbulb/relay/0/set:command:OFF:default],
            <[broker:test/lightbulb/relay/0:command:ON:1],
            <[broker:test/lightbulb/relay/0:command:OFF:0]" }

I’ve tried creating another item for controlling brightness (for example) but it don’t work and, if I say Turn on test light Google Home’s answer Ok, powering on two lights and nothing happen.

Dimmer Test_Bright "Luce test [%d %%]" [ "Lighting" ]
    { mqtt=">[broker:test/lightbulb/brightness/set:command:*:JS(dimmer-out.js)],
            <[broker:test/lightbulb/brightness:state:JS(dimmer-in.js)]" }

I’m not using sitemaps because my goal is to create a HABPanel when everything is configured properly.

I know I’m doing it wrong, but I can’t figure the right way.

Thanx in advance,
Danny

First of all your switch if configured the wrong way and you’ll end up in a command loop.

Switch Test_Light "Luce test" [ "Lighting" ] { mqtt=">[broker:test/lightbulb/relay/0/set:command:*:default], <[broker:test/lightbulb/relay/0:state:default]" }

Should suffice

What is the code of dimmer-out.js and dimmer-in.js?

The JS are a simple transformations from percentage value to 0-255.

dimmer-out.js:

(function(i) {
	if (input >= 0) {
		return input / 100 * 255;
	} else {
		return null;
	}
})(input)

dimmer-in.js:

(function(i) {
	if (input >= 0) {
		return input / 255 * 100;
	} else {
		return null;
	}
})(input)

How can be sufficent your suggestion if the bright, color, etc need another mqtt payload?

Regards,
Danny

It should be sufficient for power on/off
I didn’t mention the dimmer item

As I mention, the power on/off works.
My problems are on dimming and changing colours.

Regards,
Danny

dimmer-out.js

(function(i) {
    var input = parseInt(i);
    if (input >= 0) {
        return input / 100 * 255;
    } else {
        return null;
    }
})(input)

dimmer-in.js

(function(i) {
    var input = parseInt(i);
    if (input >= 0) {
        return input / 255 * 100;
    } else {
        return null;
    }
})(input)

Maybe I wasn’t clear in my initial post:
I’ve configured all the items in the way you have seen in my previous posts. I’ve created the sliders/buttons etc in HABPanel and, via GUI, they works perfectly:
The colors, brightness and on/off works without any problem.

My problem is that I want to do it by my voice, via Google Assistant/Google Home.

I’ve created every item with the [ “Lighting” ] tag but it don’t work.
I’ve created a group, assigned every item (of a bulb, for example) to this group and added the tag just to the group, and it don’t work.

I don’t know how I’ve to do for controlling bright and colours (by my voice) because powering on/off works.

I hope this explanation helps, for helping me :slight_smile:

Regards,
Danny

You can’t do that with OH yet

What about this?

Ok, that’s new to me

The js transform only send strings into the js script
So I changed your code so that they should work now
Before they didn’t do anything

Try the sliders in your sitemap and that should work
I don’t know about the voice control

Anyone?