xoseperez / espurna

Home automation firmware for ESP8266-based devices
http://tinkerman.cat
GNU General Public License v3.0
3k stars 636 forks source link

Add 'magichome' (zj-wfmn-c-11) single channel LED dimmer. #1999

Closed davebuk closed 4 years ago

davebuk commented 5 years ago

I have bought a single channel 'magichome' WiFi LED dimmer. I have used the env:magichome-zj-espm-5ch-b-13 environment as there is no IR connected and changed the number of channels to 1 on GPIO 12.

Can an environment for 'zj-wfmn-c-11' be created? IMG_20191119_110242 IMG_20191119_105246 IMG_20191119_105205

mcspr commented 4 years ago

Sure, is this it?

#elif defined(MAGICHOME_ZJ_WFMN_C_11)

    // Info
    #define MANUFACTURER        "MAGICHOME"
    #define DEVICE              "ZJ_WFMN_C_11"
    #define RELAY_PROVIDER      RELAY_PROVIDER_LIGHT
    #define LIGHT_PROVIDER      LIGHT_PROVIDER_DIMMER
    #define DUMMY_RELAY_COUNT   1

    // Buttons
    #define BUTTON1_PIN         0
    #define BUTTON1_MODE        BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
    #define BUTTON1_RELAY       1

    // LEDs
    #define LED1_PIN            2
    #define LED1_PIN_INVERSE    1

    // Light
    #define LIGHT_CHANNELS      1
    #define LIGHT_CH1_PIN       12      // COLD WHITE
davebuk commented 4 years ago

Yes, plus #define LIGHT_CH1_INVERSE 0.

davebuk commented 4 years ago

Is there any progress on implementing percentage values for single channel dimmers? Ref #1460

davebuk commented 4 years ago

@mcspr I have noticed that when using the above definitions, (with env:magichome-zj-espm-5ch-b-13) although I have an ON/OFF switch on the status page and the output is controlled correctly, there is nothing showing under the 'Switches' section of the webUI.

I have a magic home RGB controller as well running 1.13.6dev. That device doesn't have any BUTTONS definitions in its environment at all, but does have an entry in the 'Switches' section. I wanted my be able to set the boot status of the my single channel dimmer to ON but don't have that option in the webUI.

I have tried a build with the BUTTONS commented out but there still are not any 'Switches' listed in the webUI.

EDIT: I have also tried my custom.h version of 'zj-wfmn-a-11' and built with 1.14.0dev and that still doesn't have an entry under 'Switches'.

mcspr commented 4 years ago

See LIGHT_MAX_BRIGHTNESS and LIGHT_MAX_VALUE defines, output will scale based on those. But I think there are still some hardcoded “rogue-value / 255” that may break some interactions. Gamma too, but that does not matter for 1ch device.

Have you checked with the 1.14.0?

davebuk commented 4 years ago

Just to be clear, can I just add those to my custom.h e.g. #define LIGHT_MAX_BRIGHTNESS 100etc or temporarily modify the general.h file? I'll try building a 1.14.0 instead of the dev version tomorrow.

mcspr commented 4 years ago

Either way, there are ifndef things around them so custom.h or PIO build flags should work.

davebuk commented 4 years ago

Using the definition below in custom.h I still do not see any switches.

#elif defined(MAGICHOME_ZJ_WFMN_A_11) //_SINGLE

    // Info
    #define MANUFACTURER        "MAGICHOME"
    #define DEVICE              "ZJ_WFMN_C_11"
    #define RELAY_PROVIDER      RELAY_PROVIDER_LIGHT
    #define LIGHT_PROVIDER      LIGHT_PROVIDER_DIMMER
    #define DUMMY_RELAY_COUNT   1

    #define ALEXA_SUPPORT           0
    #define DOMOTICZ_SUPPORT        0
    #define HOMEASSISTANT_SUPPORT   0
    #define SCHEDULER_SUPPORT       0
    #define SENSOR_SUPPORT          0
    #define THINGSPEAK_SUPPORT      0
    #define LIGHT_MAX_VALUE         100
    #define LIGHT_MAX_BRIGHTNESS    100

    // Buttons
    #define BUTTON1_PIN         0
    #define BUTTON1_MODE        BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
    #define BUTTON1_RELAY       1

    // LEDs
    #define LED1_PIN            2
    #define LED1_PIN_INVERSE    1

    // Light
    #define LIGHT_CHANNELS      1
    #define LIGHT_CH1_PIN       12      // WHITE
    #define LIGHT_CH1_INVERSE   0

image

image

UPDATE: I have also installed a 1.14.0 version on my actual RGB (zj-wfmn-a-11) and that does not have any entries in the switches section. It did before when running 1.13.6-dev.

mcspr commented 4 years ago

Yep, that's a WebUI bug because of disabled scheduler: https://github.com/xoseperez/espurna/blob/978cf2af95a53232ceebd4b0cb3ac1e4758fbd74/code/html/custom.js#L1078-L1085

data.sch_last does not exist, there should be a check similar to the following:

if ("sch_last" in data) {
...
}
davebuk commented 4 years ago

I'll re-enable scheduler in my build :-) It was only disabled to reduce file size and keep under 500kB, but as i'm using core 2.5.2 and up in my builds, its not an issue now as they are always bigger and require 2-step OTA.

davebuk commented 4 years ago

@mcspr Did you want me to raise a PR for this device? It's that an easier way for you guys to track these additions?

seritos commented 4 years ago

Hi All,

I also have this Magic Home, and as far as I can see in the board, there is a channel for CW and other for WW. Shouldn't be possible to use both channels and control a White and Warm White led strip?

Thanx!

davebuk commented 4 years ago

Possibly. There does seem to be an unused solder pad. You could look to build a custom espurna build and add a second light channel. You just need to find the right GPIO assignment to control it. I don't know the code well enough, but there might be something in espurna that if more than one light channel is specified, it'll presume it's an RGB setup rather than a device with two outputs. I wouldn't know how it would treat one channel as warm white with the other as cold white, without specifying the normally corresponding RGB channels to go with them?

Maybe flash one of the 5 channel pre built .bin files and see which outputs are controlled by which light channel to find the other connected GPIO?

mcspr commented 4 years ago

Check out comment here: https://github.com/xoseperez/espurna/blob/62ad7da332f3f904ad8241a2b738be9820b196e4/code/espurna/config/general.h#L1149-L1154 https://github.com/xoseperez/espurna/blob/62ad7da332f3f904ad8241a2b738be9820b196e4/code/espurna/config/hardware.h#L3466-L3470 Just need to figure out correct GPIO value for 2nd channel

seritos commented 4 years ago

Thanx for your comments.

I have connected a led strip with two channels, every channel to each pad. Looks like the GPIO12 is connected to both channels, as I increase the brightness and both channels increases at the same time. I believe that if they would be different channels, one of them would be enabled.

I have tried to follow the electrical path, and both transistors ( for ww and cw) are connected

I don’t think I have any chance.... Don’t you think?

denes44 commented 3 years ago

I have tried to follow the electrical path, and both transistors ( for ww and cw) are connected

I don’t think I have any chance.... Don’t you think?

I bought the same controller, and now trying to figure out the GPIO numbers. As I can see, you can modify the ZJ-WFMN-C v1.1 board to a CCT board, but you need to move a resistor and that includes soldering. There are four resistors with 512 value, and two with 201 value, and a blank position. You need to move one of the 201 resistors to the blank position. The one which has the same direction as the 512 ones. So basically the board can do two channels, but it's hardware modified so both channels are controlled by the same pin from the ESP.