mikejac / node-red-contrib-google-smarthome

A collection of Node-RED nodes to control your smart home devices via Google Assistant.
GNU General Public License v3.0
116 stars 36 forks source link

Light brightness trait not exposed to Google #413

Open yschen5812 opened 1 year ago

yschen5812 commented 1 year ago

I noticed that the light device I created with 'brightness' does not show the dimmer trait in Google Home app. All I can do there is toggling the light. The color trait does work though if I check it in the device node. I can see the color temperature value being passed to node-red if I make any changes in the app. Can anyone take a look at the dimmer trait, thanks!

FireWizard52 commented 1 year ago

Hi, @yschen5812

I tested my configuration and didn't notice any issue. Can you show a screenshot of your device configuration?

Regards

Caprico85 commented 1 year ago

I can reproduce this.

image

The "Bettlampe" is connected using SmartNora and has the brigthness controls. The "Testlampe" is connected using node-red-contrib-google-smarthome and it does not have any brigthness controls.

{
        "type": "action.devices.types.LIGHT",
        "traits": [
          "action.devices.traits.Brightness",
          "action.devices.traits.OnOff"
        ],
        "name": {
          "defaultNames": [
            "Node-RED Light"
          ],
          "name": "Testlampe",
          "nicknames": []
        },
        "roomHint": "Wohnzimmer",
        "willReportState": true,
        "notificationSupportedByAgent": false,
        "attributes": {
          "commandOnlyBrightness": false,
          "commandOnlyOnOff": false,
          "queryOnlyOnOff": false
        },
        "deviceInfo": {
          "manufacturer": "Node-RED",
          "model": "nr-device-light-v1",
          "swVersion": "1.0",
          "hwVersion": "1.0"
        },
        "otherDeviceIds": [
          {
            "deviceId": "1bbb378b69bd4748"
          }
        ],
        "customData": {},
        "id": "1bbb378b69bd4748"
      }

This seems to happen when the device has not received any brightness values yet. After I injected a on and a brightness value, the brightness controls started working.

I see if I can automatically inject default values on restart. In the meantime, you can try an inject node to automatically inject values.

image

The second value is msg.payload.brightness. Set the injection time high enough to give it some time before sending.

yschen5812 commented 1 year ago

@FireWizard52 For my case I'm only using this node as a subscriber that syncs whatever dimmer value in Google Home to my node-red flow so I was not sending any command to the node. @Caprico85's simple workaround solves my problem. Thanks both of you for taking your time looking into this issue.

I'm good with closing this issue without a fix to make the injection happen on restart, but I'll leave it to you.

Caprico85 commented 11 months ago

I'll leave it open until I (or somebody else) has implemented a fix to automatically inject default values at boot. Might also fix some other problems where devices behave "strange" after a restart.

FireWizard52 commented 11 months ago

Hello @Caprico85 and @yschen5812,

I now really understand, what your issue was.

  1. I use the manual controls in the Google Home app very seldom.
  2. I use Shelly Dimmer 2 and I have also the Shelly apps and the default wall switch available.
  3. I use also Domoticz.
  4. I have always the input of the device connected to other nodes and after a restart I always request the actual status of the lights, either from Domoticz or (preferred) directly from the Shelly device and inject the actual value into the device.

I would not be happy if @Caprico85 creates a fix in such a way that by default always an On/Off value and a brightness of 0 is injected and that that overrides my Inject of the actual status. My "default at boot" is always the actual status!

Thanks for your work on this application.

Regards

yschen5812 commented 11 months ago

I think I agree with @FireWizard52 to avoid injecting fixed default values on every restart. It seems like the only goal is to make Google Home to notice the "brightness" attribute of the device so it would be better to leave the values along if possible. If the only way to flag the attribute to Google Home is via setting values then maybe better to serve with values from previous state.

ckhmer1 commented 10 months ago

Hi All, it is possible to store to permanent storage the node status and inject the last status back on the node. You need to add some login in input and output to the management node.

Caprico85 commented 8 months ago

On a second thought, I have to agree. Setting new default values on every restart is not good. Especially since every deployment in Node-RED means the service is restarted so you're constantly losing your states.

A better solution would probably be to query the HomeGraph for the current values and set only the states that are not already set. This would also provide an easier way to restore the current values on startup.