i8beef / HomeAutio.Mqtt.GoogleHome

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mapping different range [0,99] to [0,254]

balthus opened this issue · comments

Hello,
First of all, many thanks for sharing your code and also the useful doc. I could make some working POC in few hours (knowing nothing about google home/actions...
I have few system running here (zigbee/zwave 2 mqtt) and with the zigbee, some lamps needs a brightness range from 0 to 254.

I don't know how/where to specify that the final value should be remapped to a different range.
I'm currently using this:

     {
          "trait": "action.devices.traits.Brightness",
          "commands": { "action.devices.commands.BrightnessAbsolute": { "brightness": "zigbee2mqtt/living_room_ceiling_lights/brightness" } },
          "state": {
            "brightness": {
              "topic": "zigbee2mqtt/living_room_ceiling_lights/brightness",
              "googleType": "numeric",
              "valueMap": [
                {
                  "mqtt": "254",
                  "type": "value",
                  "google": "99"
                },
                {
                  "mqtt": "0",
                  "type": "value",
                  "google": "0"
                }
              ]
            }
          }
        }

I know that it's not correct and also I can set the absolute brightness from 0->98 and at 99 it's mapped to 254.
Is this mapping currently supported?
What/how to make it work?
Sorry if it's not a bug, but I tried to look in the wiki/issue but didn't find so far any answer.
Could be also helpful to add such example in the devices.json

Many Thanks,

Laurent

Note:
Just realizing that I have similar issue with the color temperature of the lights. It expect a range between 150(cold white) ->500(warm white)

There is not a valueMap in place that will do calculated range mappings, no. I can look at possibly adding that after I get this major release out the door.

If you happen to have node-red in your setup, you can do the translation yourself. You can use command delegation mode to process the command yourself in node-red and send the right MQTT messages out. And you can bind your STATE topics to a DIFFERENT topic, which you publish the translated values to instead of the original topic (again, translation in node-red).

Hello,

Thanks, at least, I know there is no config for the moment to support that. I think it could be a useful not so hard enhancement.
Some devices use exotic ranges that are not in [0,99].
In the case of my light bulb(https://www.zigbee2mqtt.io/devices/RB_278_T.html), the range is from [0,254] for brightness and [150,500] for the color temperature.
I will see with the command delegation. It makes it a bit more complex and require a third party (nodered, but I also use it) to do conversion.
It's also possible to use mqttDash (android application) to control/tune it.

Best regards,

ps: Please, feel free to close this issue or convert it to enhancement

I just released 2.0. It will include a new valuMap called "linearRange" that you can use for this, definined as follows:

...
"valueMap": [
  {
    "type": "linearRange",
    "googleMin": 0,
    "googleMax": 99,
    "mqttMin": 0,
    "mqttMax": 254
  }
]

Other documentation incoming in a new topic on 2.0 changes, you might have to modify your certs to get this running.

Hello,
That was really quick :) 👍
I just tried and it seems to work (although google home seems a bit sluggish to propagate those changes on an other device( ie changing from phone and checking on wife phone)
Anyway many thanks.
Just in case, here is my config in case other people would try to make it work:

  "google/home/livingroom/ceiling/lights": {
    "id": "google/home/livingroom/ceiling/lights",
    "type": "action.devices.types.LIGHT",
    "willReportState": false,
    "roomHint": "Living room",
    "name": {
      "defaultNames": [],
      "name": "Ceiling lights",
      "nicknames": []
    },
    "deviceInfo": {
      "manufacturer": "Some Company",
      "model": "Some Model",
      "hwVersion": "1.0",
      "swVersion": "1.0"
    },
    "traits": [
      {
        "trait": "action.devices.traits.OnOff",
        "commands": {
          "action.devices.commands.OnOff": {
            "on": "zigbee2mqtt/living_room_ceiling_lights/set/state"
          }
        },
        "state": {
          "on": {
            "topic": "zigbee2mqtt/living_room_ceiling_lights",
            "googleType": "bool",
            "valueMap": [
              {
                "type": "regex",
                "googleReplace": "true",
                "mqttSearch": ".*state\":\"ON\".*"
              },
              {
                "type": "regex",
                "googleReplace": "false",
                "mqttSearch": ".*state\":\"OFF\".*"
              },
              {
                "mqtt": "ON",
                "type": "value",
                "google": "true"
              },
              {
                "mqtt": "OFF",
                "type": "value",
                "google": "false"
              }
            ]
          }
        }
      },
      {
        "trait": "action.devices.traits.Brightness",
        "commands": {
          "action.devices.commands.BrightnessAbsolute": {
            "brightness": "zigbee2mqtt/living_room_ceiling_lights/set/brightness"
          }
        },
        "state": {
          "brightness": {
            "topic": "zigbee2mqtt/living_room_ceiling_lights",
            "googleType": "numeric",
            "valueMap": [
              {
                "type": "regex",
                "googleReplace": "$1",
                "mqttSearch": ".*brightness\":([0-9]+).*"
              },
              {
                "type": "linearRange",
                "googleMin": 0,
                "googleMax": 100,
                "mqttMin": 0,
                "mqttMax": 254
              }              
            ]
          }
        }
      },
      {
        "trait": "action.devices.traits.ColorSetting",
        "attributes": {
          "colorModel": "rgb",
          "colorTemperatureRange": {
            "temperatureMinK": 2000,
            "temperatureMaxK": 6500
          },
          "commandOnlyColorSetting": false
        },
        "commands": {
          "action.devices.commands.ColorAbsolute": {
            "color.name": "zigbee2mqtt/living_room_ceiling_lights/set/color_temp"
          }
        },
        "state": {
          "color.name": {
            "topic": "1",
            "googleType": "string",
            "valueMap": [
              {
                "mqtt": "150",
                "type": "value",
                "google": "ivory"
              },
              {
                "mqtt": "200",
                "type": "value",
                "google": "daylight"
              },
              {
                "mqtt": "250",
                "type": "value",
                "google": "cool white"
              },
              {
                "mqtt": "300",
                "type": "value",
                "google": "warm white"
              },
              {
                "mqtt": "400",
                "type": "value",
                "google": "incandescent"
              },
              {
                "mqtt": "500",
                "type": "value",
                "google": "candlelight"
              }
            ]
          }
        }
      }
    ]
  }

To change light color, it uses few names from the google home app and map them to some predefined values.
The brightness uses your new linearRange.
I also have to extract the mqtt json value via a regexp
I had no issue so far with the new 2.0 release and with certificates as your application runs in a docker container and I use a pfsense router with ha_proxy(+ssl)

Best regards,

Laurent

Closing as fixed! Thanks for the suggestion!