logo elektroda
logo elektroda
X
logo elektroda

Scripting ADC light sensor for LSC Sensor LED Flood Light BK7231T

piotrszulc1 699 4
ADVERTISEMENT
  • #1 20756065
    piotrszulc1
    Level 9  
    >>20041909
    Hi, I have 2 such lamps, both on cloudcutter and recently decided to flash one with openbk. Flashing (via OTA) went smoothly, but since Openbk is new to me, I had to do a lot of reading before I understand how it all works.
    I spent some time fiddling around the various pins & roles and eventually got to the working configuration. Only then I found the above post of @darkman11 :) and it confirms I got the configuration right. But, as he/she wrote this more than a year ago, I am wondering if ADC is now implemented in OpenBK?
    I actually have some readings from ADC channel.
    When it's dark:
    
    Channel 4 = 3761.00
    

    When I flash some light at the sensor, the value goes down quite low, even to a 3-digit number (ca. 200), then it goes back up to ~3764 when the light is removed. Does this mean it is usable now for scripting?
  • ADVERTISEMENT
  • #2 20756411
    p.kaczmarek2
    Moderator Smart Home
    ADC should work, I tested it many times with potentiometers, what kind of light sensor do you have?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20759776
    piotrszulc1
    Level 9  
    I have no idea what sensor this is, I don't really want to open the lamp if this isn't absolutely necessary...
    ADC does seem to work and I've created a simple script to turn on the light automatically on PIR after dark.

    
    alias schedule_light_off addRepeatingEventID 10 -1 123 led_enableAll 0
    alias trigger_light backlog led_enableAll 1; cancelRepeatingEvent 123
    AddChangeHandler Channel3 == 1 if $CH4>1000 then trigger_light
    AddChangeHandler Channel3 == 0 schedule_light_off
    


    The trigger values were selected somewhat arbitrary, this is still WIP.
    For the script to work correctly, the configuration must be as follows:

    
    {
      "vendor": "LSC",
      "bDetailed": "0",
      "name": "LSC Sensor LED Flood Light",
      "model": "3003366",
      "chip": "BK7231T",
      "board": "TODO",
      "flags": "267264",
      "keywords": [
        "LSC",
        "Floodlight"
      ],
      "pins": {
        "6": "dInput;3",
        "8": "PWM;1",
        "9": "PWM;2",
        "23": "ADC;4"
      },
      "command": "",
      "image": "https://templates.blakadder.com/assets/device_images/lsc_smart_connect_3003366.webp",
      "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }
    


    I'd like to re-create the functionality of the original Tuya firmware, but I have some questions:

    1) I want to allow the end user to be able to set the level of ambient light at which the lamp activates on PIR. For this I will select some ADC values (experimentally) and define a dedicated mqtt topic that will allow the user to set/get this setting. Is there a way to store this setting in the flash? Also, I will probably need to use some kind of variable in the script, are these available or do I have to use channells?

    2) The original firmware allowed the user to select the sensitivity of PIR sensor (ie. proximity of it detecting movement) - close/normal/far. However, the PIR sensor seems to always work the same way (sets 1 to dinput on movement and resets back to 0 after ~2 seconds if there is no movement). Do you have any idea how to realize this functionality with such a "primitive" setup? Or maybe I'm missing something and there should be a way to configure PIR?
  • ADVERTISEMENT
  • #4 20780008
    p.kaczmarek2
    Moderator Smart Home
    Very good progress with the script, however I would like to note that it could be easier to do it as a C driver.

    I saw your issue there: https://github.com/openshwprojects/OpenBK7231T_App/issues/936

    piotrszulc1 wrote:

    1) I want to allow the end user to be able to set the level of ambient light at which the lamp activates on PIR. For this I will select some ADC values (experimentally) and define a dedicated mqtt topic that will allow the user to set/get this setting. Is there a way to store this setting in the flash? Also, I will probably need to use some kind of variable in the script, are these available or do I have to use channells?

    I think that if you set given channel to be remembered in flash (it works for first few channels, so lets say channel 2) it should work


    I will also answer questions from Github:
    Quote:

    However, the "additional rule" is problematic with mqtt, because I would have to prevent HomeAssistant from changing most of the variables directly, since I would have no way of detecting that change came from HA and not from the script itself (is there a way to detect this)?

    Maybe, just maybe, set a dummy "ghost" channel with change callback, and let HA control via this dummy channel?


    Quote:
    ). This proves to work fine as long as the command does not require parameters, as there's no way to define parameters for aliases in the script (is there?).

    There is no way currently to do this, but if you have any idea how it should work on the surface, I can implement it for you.
    Helpful post? Buy me a coffee.
  • #5 21194730
    Frank579
    Level 2  
    Hallo,
    Ich hoffe es ist okay, wenn ich auf Deutsch schreibe, mein Englisch ist grauenhaft :)
    Hast du hier eine Lösung gefunden? Ich habe den gleichen Strahler von LSC und würde ihn dann auch gerne flashen, bin aber erst 2 Tage mit OpenBeken beschäftigt ..

    Hello,
    I hope it's okay if I write in German, my English is terrible :)
    Did you find a solution here? I have the same spotlight from LSC and would like to flash it, but I've only been busy with OpenBeken for 2 days..
ADVERTISEMENT