Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support phillips hue power on behaviour #746

Closed
danpowell88 opened this issue Dec 22, 2018 · 31 comments
Closed

Support phillips hue power on behaviour #746

danpowell88 opened this issue Dec 22, 2018 · 31 comments
Labels
stale Stale issues

Comments

@danpowell88
Copy link

In the latest hue light firmware (SW 1.46.13_r26312) support has been added for allowing the bulb to return to its previous state after a power outage.

I've capture the zigbee traffic when setting a bulb to have the option and the following is the dump.

Can we add support for specifying this.

Setting it to Power loss recovery (last used colour and brightness) generates the following two packets
image

image

Setting it to off (light always powers on with warm white full brightness) generates the following two packets
image

image

@danpowell88
Copy link
Author

danpowell88 commented Dec 23, 2018

I think I've managed to get part of the way there.

Looks like it requires changes in https://github.com/zigbeer/zcl-id/blob/master/definitions/cluster_defs.json

to add the following

to 'genOnOff'
"powerOnCtrl":{"id":16387,"type":"enum8"}},

to 'genLevelControl'
"powerOnCtrl":{"id":16384,"type":"uint8"}},

then in zigbee-shepherd-converters something like

configure: (ieeeAddr, shepherd, coordinator, callback) => {
            const device = shepherd.find(ieeeAddr, 1);
            const actions = [
                (cb) => device.write('genOnOff', 'powerOnCtrl', 255, cb),
				(cb) => device.write('genLevelCtrl', 'powerOnCtrl', 255, cb)
            ];
            execute(device, actions, callback);
        }	

To all hue bulbs.

Unfortunately after doing this I get an error that z2mqtt failed to configure the lights, and I cant see any more debug information, even when running with debug log level and the DEBUG environment variable

Koenkk added a commit to Koenkk/zigbee-herdsman-converters that referenced this issue Dec 25, 2018
@Koenkk
Copy link
Owner

Koenkk commented Dec 25, 2018

Instead of adding it to configure I think it's better to have a converters for this.

Please checkout https://github.com/Koenkk/zigbee-shepherd-converters/tree/hue_power_behaviour

You should be able to control the power on by sending to zigbee2mqtt/[DEVICE_ID]/set value:

{
  "power_on_behaviour_1": "recover",   // recover or off
  "power_on_behaviour_2": "recover",  // recover or off
}

Let me know if this works, if so, I can refactor zigbee-shepherd-converters so that you only have to send power_on_behaviour.

@danpowell88
Copy link
Author

danpowell88 commented Dec 26, 2018

Didnt appear to work

�[34m zigbee2mqtt:debug�[39m 2018-12-26 11:03:45 Received MQTT message on 'zigbee2mqtt/0x00178801035609f4/set' with data '{
"power_on_behaviour_1": "recover",
"power_on_behaviour_2": "recover",
}'
�[32m zigbee2mqtt:info�[39m 2018-12-26 11:03:45 Zigbee publish to '0x00178801035609f4', genOnOff - {
"power_on_behaviour_1": "recover",
"power_on_behaviour_2": "recover",
} - {} - {"manufSpec":0,"disDefaultRsp":0} - null
�[31m zigbee2mqtt:error�[39m 2018-12-26 11:03:45 Zigbee publish to '0x00178801035609f4', genOnOff - {

"power_on_behaviour_1": "recover",
"power_on_behaviour_2": "recover",
} - {} - {"manufSpec":0,"disDefaultRsp":0} - null failed with error Error: Unrecognized command

@Koenkk
Copy link
Owner

Koenkk commented Dec 27, 2018

I don't understand why this error is thrown, are you on the latest (clean) dev branch?

@danpowell88
Copy link
Author

danpowell88 commented Dec 27, 2018 via email

@danpowell88
Copy link
Author

@Koenkk Tried it again on a clean rapsberry pi with the full dev branch

zigbee2mqtt:info 12/28/2018, 7:28:44 AM Starting zigbee2mqtt version 1.0.1 (commit #5e4e6d8)
zigbee2mqtt:info 12/28/2018, 7:28:44 AM Starting zigbee-shepherd
zigbee2mqtt:info 12/28/2018, 7:28:46 AM zigbee-shepherd started
zigbee2mqtt:info 12/28/2018, 7:28:46 AM Coordinator firmware version: '20181024'  
zigbee2mqtt:info 12/28/2018, 7:29:13 AM Zigbee publish to device '0x00178801035609f4', genOnOff - {  "power_on_behaviour_1": "recover",   // recover or off  "power_on_behaviour_2": "recover",  // recover or off} - {} - {"manufSpec":0,"disDefaultRsp":0} - null
zigbee2mqtt:error 12/28/2018, 7:29:13 AM Zigbee publish to device '0x00178801035609f4', genOnOff - {  "power_on_behaviour_1": "recover",   // recover or off  "power_on_behaviour_2": "recover",  // recover or off} - {} - {"manufSpec":0,"disDefaultRsp":0} - null failed with error Error: Unrecognized command

I also manually modified the package.json to change the following

"zigbee-shepherd-converters": "git+https://github.com/Koenkk/zigbee-shepherd-converters.git#6d49008e91c7606c9067be8c469e898cb2e5a0b2"

Taking a quick look at toZigbee.js in converts it appeared to have the power on change so I assume this was correct

@danpowell88
Copy link
Author

Just figured it out!

It was the comment in the json that was causing the issue, will test it now

@danpowell88
Copy link
Author

@Koenkk success, tested with recover and off and both worked as expected

@Koenkk
Copy link
Owner

Koenkk commented Dec 28, 2018

Great! Do you also have color or color temperature bulbs? If yes, can you check if that is also recovered?

@danpowell88
Copy link
Author

danpowell88 commented Dec 28, 2018 via email

@danpowell88
Copy link
Author

Brightness if maintained but not colour, I'll have to pull out the sniffer again and see if something different is sent for the colour retention

@danpowell88
Copy link
Author

danpowell88 commented Dec 28, 2018

In addition to the above two attributes it sends the following for a colour bulb

Looks like it sends the following for colour retention on

Cluster: Color Control (0x0300)
Profile: Home Automation (0x0104)
Command: Write Attributes (0x02)
Attribute: 0x4010
Data Type: 16-bit unsigned integer (0x21)
Value: 65535 (0xffff)

Cluster: Color Control (0x0300)
Profile: Home Automation (0x0104)
Command: Write Attributes (0x02)
Attribute: 0x0003
Data Type: 16-bit unsigned integer (0x21)
Value: 65535 (0xffff)
Cluster: Color Control (0x0300)
Profile: Home Automation (0x0104)
Command: Write Attributes (0x02)
Attribute: 0x0004
Data Type: 16-bit unsigned integer (0x21)
Value: 65535 (0xffff)

The last 2 also specify a manufacturer code Phillips (0x100b)
1
2
3
4
5

@danpowell88
Copy link
Author

Also just a note along with comments it doesnt like a trailing comma on the final attribute

@Koenkk
Copy link
Owner

Koenkk commented Dec 29, 2018

And what is send for the normal behaviour?

@Chrischi-
Copy link
Contributor

Chrischi- commented Jan 9, 2019

This worked for me to set the power-on behavior.

"manufacturerName":"Philips",
"modelId":"LTW013",
"swBuildId":"1.46.13_r26312"
// enable/disable/configure power on behavior, 
// default = 1
// off - lamps off after power loss, 
// on - lamps on after power loss with configured level (bri), color temp, color
// recover - lamps on after power loss with last state
    hue_power_on_behavior: {
        key: ['power_on_behavior'],
        convert: (key, value, message, type) => {
            const lookup = {
                'off': 0x00,
                'on': 0x01,
                'recover': 0xff,
            };

            if (type === 'set') {
                return {
                    cid: 'genOnOff',
                    cmd: 'write',
                    cmdType: 'foundation',
                    zclData: [{
                        attrId: 0x4003,
                        dataType: 0x30,
                        attrData: lookup[value],
                    }],
                    cfg: cfg.default,
                };
            }
        },
    },

// brightness when power-on behavior = on, same settings as brightness converter
// default = 255
    hue_power_on_level: {
        key: ['power_on_level'],
        convert: (key, value, message, type) => {
            if (type === 'set') {
                return {
                    cid: 'genLevelCtrl',
                    cmd: 'write',
                    cmdType: 'foundation',
                    zclData: [{
                        attrId: 0x4000,
                        dataType: 0x20,
                        attrData: value,
                    }],
                    cfg: cfg.default,
                };
            }
        },
    },

// color temperature when power-on behavior = on, same settings as colortemp converter
// default = 366
    hue_power_on_temp: {
        key: ['power_on_color_temperature'],
        convert: (key, value, message, type) => {
            if (type === 'set') {
                return {
                    cid: 'lightingColorCtrl',
                    cmd: 'write',
                    cmdType: 'foundation',
                    zclData: [{
                        attrId: 0x4010,
                        dataType: 0x21,
                        attrData: value,
                    }],
                    cfg: cfg.default,
                };
            }
        },
    },

@Koenkk
Copy link
Owner

Koenkk commented Jan 9, 2019

@Chrischi- great, could you make a pr?

@Chrischi-
Copy link
Contributor

@Koenkk
any idea to put this into one converter?

if you switch on the behavior, you should have the possibility to set
the color, color-temperature and brightness. since i don't have
colored lamps (only color temperature and brightness), i can't
create a converter for it

@Koenkk
Copy link
Owner

Koenkk commented Jan 9, 2019

I don't think that these converters should be merged together, they each serve a different purpose.

Could you prefix the keys with hue_? (as this is hue specific, e.g. key: 'hue_power_on_color_temperature'],

Ofcourse all the attributes can be set using 1 MQTT message:

{
  "hue_power_on_behavior": "on",
  "hue_power_on_level": 200,
  "hue_power_on_color_temperature": 300
}

@stale
Copy link

stale bot commented Mar 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale issues label Mar 10, 2019
@Koenkk Koenkk closed this as completed Mar 11, 2019
@bepece1
Copy link

bepece1 commented Oct 22, 2019

Also work right in Tuya, Tadfradi or Sonoff lights????

@victoriano95
Copy link

Hi, I'm trying to set this option and it'is not working, these are the details:
Topic: zigbee2mqtt/friendlyName/set
Payload:

{
    "hue_power_on_behavior": "recover"
}

When I cut the power to the bulb and I restore it again it turns on.
The log output is:{"ieeeAddr":"0x001788010424184b","type":"Router","networkAddress":14471,"model":"8718696548738","friendly_name":"0x001788010424184b","manufacturerID":4107,"manufacturerName":"Philips","powerSource":"Mains (single phase)","modelID":"LTW010","hardwareVersion":1,"softwareBuildID":"1.50.2_r30933","dateCode":"20191218","lastSeen":1583688566569}]}'

@Chrischi-
Copy link
Contributor

Hi, I'm trying to set this option and it'is not working, these are the details:
Topic: zigbee2mqtt/friendlyName/set
Payload:

{
    "hue_power_on_behavior": "recover"
}

When I cut the power to the bulb and I restore it again it turns on.

recover - lamps on after power loss with last state

@victoriano95
Copy link

I want to recover or power off the bulbs when the power is restored but I when I send the command I can't see nothing on the log and it is not activating the option on the bulb

@sjorge
Copy link
Contributor

sjorge commented Mar 17, 2020

@victoriano95 after upgrading my bulb yesterday with the experimental hue update support.
I too thought it did not work, but it did for me. Before the bulb recovered to the previeus state it had to be without power for a good few seconds.

And indeed, there is no logging for the command.

@victoriano95
Copy link

@victoriano95 after upgrading my bulb yesterday with the experimental hue update support.
I too thought it did not work, but it did for me. Before the bulb recovered to the previeus state it had to be without power for a good few seconds.

And indeed, there is no logging for the command.

Can you explain me what commands are you sending and what is the correct mqtt toppic? I have tried to leave the bulb a few minutes unplugged and it's still on when the power is recovered.
Thanks
@sjorge

@sjorge
Copy link
Contributor

sjorge commented Mar 17, 2020

In my case it was

{
    "hue_power_on_behavior": "recover"
}

to zigbee2mqtt/<friendlyname>/set

But also pay attemtion to

Rules:

    * hue_power_on_behavior value always has to be provided
    * hue_power_on_brightness, hue_power_on_color_temperature and hue_power_on_color can only be provided when hue_power_on_behavior = on
    * hue_power_on_color_temperature and hue_power_on_color cannot be provided together, only one can be set
    * When setting hue_power_on_behavior = on, any not provided values will be reset to their factory defaults

@victoriano95
Copy link

victoriano95 commented Mar 17, 2020

When you send this command the bulb turns off? it's ok the comma?

{
    "hue_power_on_behavior": "recover",
}

I'm sending the same command at the correct toppic, when I send it without comma it's not any output at the log and when I send it with the comma this is the output:
MQTT publish: topic 'zigbee2mqtt/0x001788010424194b', payload '{"state":"OFF","brightness":0,"color_temp":451}'
What is your FW version?

@sjorge
Copy link
Contributor

sjorge commented Mar 17, 2020

The comma was an error, I correct it above. When I sent it there was no response in the logs. That is normal.

I then turned off the bulb, cut the power to the bulb for 15sec and when I restored the power the bulb remained of.

I then turned on the bulb, cut the power to the bulb for 15sec and when I restored the power the bulb turned on again... so I think it is working.

@victoriano95
Copy link

@sjorge Thanks, the problem was my zigbee2mqtt version, I have updated it and it works fine.

@kedare
Copy link

kedare commented Sep 1, 2021

Is there a way to set this using the web interface ? If not it's not very clear how to inject messages in the MQTT ? ('m using home assistant with the embedded mosquitto)

@PostLogical
Copy link

Is there a way to set this using the web interface ? If not it's not very clear how to inject messages in the MQTT ? ('m using home assistant with the embedded mosquitto)

Just went through this myself. I'm using Home Assistant in a docker container, so apologies if anything is different for HA OS or others, but you should be able to go to your Integrations page in Home Assistant and click on Configure for the MQTT integration. Then there are only a few things on the screen including "Publish a packet." Put in the topic as discussed above zigbee2mqtt/FRIENDLYNAME/set. And then put in the payload below that (see above for options). There isn't any feedback once you click Publish, so to confirm your command reached zigbee2mqtt, you might go to your Zigbee2MQTT interface and open the log and choose debug as log level before publishing the command. If you did it right, the command will appear in the log under debug (and only under debug).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues
Projects
None yet
Development

No branches or pull requests

8 participants