logo elektroda
logo elektroda
X
logo elektroda

Turning Off LED on Tuya AU LSPA9 Smart Socket After Successful Openbeken Flash

ciknururko 3903 57
ADVERTISEMENT
  • #31 20801972
    ciknururko
    Level 3  

    Thank you.... Changed as suggested by you. Working now as needed.

    Please guide me on the following:-

    I have set CH15 as the inching timer. Can I update this text field value from Home Assistant?

    Kindly guide
  • ADVERTISEMENT
  • #32 20802077
    p.kaczmarek2
    Moderator Smart Home
    Of course, the whole idea of channels is to be fully scriptable variables.

    You can refer to our documentation here:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/mqttTopics.md

    You can publish data to channel MQTT topic and listen to it, here are details:
    Table showing information on MQTT topics, sample values, and descriptions for OpenBeken.
    You can use channel data in anyway you like, just use Home Assistant configuration.yaml script to adjust HA behaviour to your needs.
    Helpful post? Buy me a coffee.
  • #33 20802308
    ciknururko
    Level 3  
    Thank you worked....
  • #34 20802372
    p.kaczmarek2
    Moderator Smart Home
    Can you please post here your full autoexec.bat, device config, and HASS Yaml, so our readers can also use those scripts? Thanks!
    Helpful post? Buy me a coffee.
  • #35 20803372
    ciknururko
    Level 3  

    Here is my HASS YAML

    Code: YAML
    Log in, to see the code


    and autoexec.bat

    
    setChannelType 2 TimerSeconds
    alias turn_off_after_time backlog setChannel 2 $CH15
    alias on_turned_off setChannel 2 0
    alias turn_off_relay setChannel 1 0
    alias do_check if $CH2==0 then turn_off_relay 
    alias do_tick backlog addChannel 2 -1; do_check
    addChangeHandler Channel1 == 1 turn_off_after_time 
    addChangeHandler Channel1 == 0 on_turned_off
    again:
    if $CH2!=0 then do_tick
    delay_s 1
    goto again

  • ADVERTISEMENT
  • #36 20819079
    ciknururko
    Level 3  

    >>20802077
    Hi,

    I have two queries:

    1. In addition to my current autoexec.bat, how can I set a time function so that at a specified time the switch gets TURN ON or TURN OFF?
    e.g. if current_time == 17:00, turn off switch.

    2. How to make the switch turn on after 5 seconds when the main power to the switch is turned on?

    Kindly guide.
  • #37 20819243
    p.kaczmarek2
    Moderator Smart Home
    ciknururko wrote:

    1. In addition to my current autoexec.bat, how can I set a time function so that at a specified time the switch gets TURN ON or TURN OFF?
    e.g. if current_time == 17:00, turn off switch.

    This can be done with addClockEvent function.
    Screenshot of addClockEvent documentation in the OpenBK7231T_App GitHub project.
    Read more at:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    NTP must be run in order for clock events to work.

    ciknururko wrote:

    2. How to make the switch turn on after 5 seconds when the main power to the switch is turned on?

    Let me ask, by main power, you mean after the plug got mains power? After the reboot?
    Well, if that's the case, use the following script:
    
    // your current autoexec.bat here
    
    // now delay
    delay_s 5
    // now power ON
    POWER ON
    

    Alternatively, you can manipulate channels there:
    
    // your current autoexec.bat here
    
    // now delay
    delay_s 5
    // now power ON
    setChannel 1 1
    

    Alternatively, you can use an event:
    
    // This command will turn on relay on CH1 after 10 seconds
    // addRepeatingEvent	[IntervalSeconds][RepeatsOr-1][CommandToRun]
    addRepeatingEvent 10 1 setChannel 1 1
    

    Let me know if you have any futher questions or guidance.
    Helpful post? Buy me a coffee.
  • #38 20819295
    ciknururko
    Level 3  
    p.kaczmarek2 wrote:
    // your current autoexec.bat here

    // now delay
    delay_s 5
    // now power ON
    POWER ON


    worked.... thank you

    Added after 5 [minutes]:

    p.kaczmarek2 wrote:
    This can be done with addClockEvent function.


    setChannelType 2 TimerSeconds
    alias turn_off_after_time backlog setChannel 2 $CH15
    alias on_turned_off setChannel 2 0
    alias turn_off_relay setChannel 1 0
    alias do_check if $CH2==0 then turn_off_relay 
    alias do_tick backlog addChannel 2 -1; do_check
    addChangeHandler Channel1 == 1 turn_off_after_time 
    addChangeHandler Channel1 == 0 on_turned_off
    
    startDriver ntp
    ntp_timeZoneOfs +05:30
    alias plug_on backlog POWER ON
    
    waitFor NTPState 1
    if $hour>=14&&$hour<21 then plug_on
    
    again:
    if $CH2!=0 then do_tick
    delay_s 1
    goto again



    1. I have set inching of 10 seconds via GUI just for testing purposes(plug should turn off after 10 seconds).
    2. The plug gets turn on if $hour>=14&&$hour<21 but it doesn't get turn off automatically after 10 seconds.

    Am I doing something wrong here?

    Added after 22 [minutes]:

    Also can I call some other file from within autoexec.bat

    e.g

    //autoexec.bat
    //some commands in autoexec.bat
    function.bat
    
    //function.bat (this is another file created)
    startDriver ntp
    ntp_timeZoneOfs +05:30
    delay_s 5
    POWER ON
    
  • ADVERTISEMENT
  • #40 20821983
    p.kaczmarek2
    Moderator Smart Home
    1. Maybe you can try using setChannel instead of POWER, but both should work.
    Change:
    
    alias plug_on backlog POWER ON
    

    to:
    
    alias plug_on backlog setChannel 1 1
    

    This should call:
    
    addChangeHandler Channel1 == 1 turn_off_after_time 
    

    if not, I will have to test for a bug in the scripting and fix it.


    2. You can use startScript:
    
    startScript	[FileName] [Label] [UniqueID]
    

    like:
    
    startScript myBat.bat * 12345
    

    NOTE: the ID 12345 can be used to cancel script later
    Helpful post? Buy me a coffee.
  • #41 20822030
    ciknururko
    Level 3  
    p.kaczmarek2 wrote:
    startScript myBat.bat * 12345


    Worked....

    Added after 4 [minutes]:

    p.kaczmarek2 wrote:
    alias plug_on backlog setChannel 1 1


    setChannelType 2 TimerSeconds
    alias turn_off_after_time backlog setChannel 2 $CH15
    alias on_turned_off setChannel 2 0
    alias turn_off_relay setChannel 1 0
    alias do_check if $CH2==0 then turn_off_relay 
    alias do_tick backlog addChannel 2 -1; do_check
    addChangeHandler Channel1 == 1 turn_off_after_time 
    addChangeHandler Channel1 == 0 on_turned_off
    
    startDriver ntp
    ntp_timeZoneOfs +05:30
    alias plug_on backlog setChannel 1 1
    
    waitFor NTPState 1
    if $hour>=14&&$hour<21 then plug_on
    
    again:
    if $CH2!=0 then do_tick
    delay_s 1
    goto again



    still not working after changing as suggested by you..... The plug gets TURN ON but doesn't TURN OFF after "10 seconds" which is set using GUI
    Screenshot of an interface with the Toggle 1 button turned on, an entry field Change channel 15 value set to 10, and a Set! button below.

    Kindly check and guide
  • #42 20822140
    p.kaczmarek2
    Moderator Smart Home
    I need to check on my side, but what about a temporary workaround?
    Change:
    
    alias plug_on backlog setChannel 1 1
    

    To:
    
    alias plug_on backlog setChannel 1 1; turn_off_after_time 
    

    Maybe that can help.
    Helpful post? Buy me a coffee.
  • #44 20822736
    p.kaczmarek2
    Moderator Smart Home
    I think it is working, there is another problem.

    Most likely your channel 15 is 0.

    That would cause delay to be non-existent.

    Here is my current version that fixes channel 15 and makes sure it has non zero value:
    
    
    // TODO: adjust second 15 here
    setChannel 15 15
    
    setChannelType 15 TextField
    setChannelLabel 15 TurnOffTime
    setChannelType 2 TimerSeconds
    alias turn_off_after_time backlog setChannel 2 $CH15
    alias on_turned_off setChannel 2 0
    alias turn_off_relay setChannel 1 0
    alias do_check if $CH2==0 then turn_off_relay 
    alias do_tick backlog addChannel 2 -1; do_check
    addChangeHandler Channel1 == 1 turn_off_after_time 
    addChangeHandler Channel1 == 0 on_turned_off
    
    startDriver ntp
    ntp_timeZoneOfs 1
    alias plug_on backlog setChannel 1 1
    
    waitFor NTPState 1
    if $hour>=14&&$hour<21 then plug_on
    
    again:
    if $CH2!=0 then do_tick
    delay_s 1
    goto again
    

    Tested on BK7231 device:
    Eurobatt power strip with connected adapter and activated switch.
    Helpful post? Buy me a coffee.
  • #45 20823009
    ciknururko
    Level 3  

    This worked....

    But the timer is hardcoded to 15 seconds (or whatever we set it). I was hoping to set the timer from Home Assistant, which I was doing in my version of the script.

    Is it not possible to achieve the same without hardcoding??

    Kindly guide.
  • #46 20823023
    p.kaczmarek2
    Moderator Smart Home
    Only first 10 channels or so can be retained.

    So you need to change channel 15 to let's say 5 and then set start value to "-1" which means "save in flash":
    
    
    setStartValue 5 -1
    setChannelType 5 TextField
    setChannelLabel 5 TurnOffTime
    setChannelType 2 TimerSeconds
    alias turn_off_after_time backlog setChannel 2 $CH5
    alias on_turned_off setChannel 2 0
    alias turn_off_relay setChannel 1 0
    alias do_check if $CH2==0 then turn_off_relay 
    alias do_tick backlog addChannel 2 -1; do_check
    addChangeHandler Channel1 == 1 turn_off_after_time 
    addChangeHandler Channel1 == 0 on_turned_off
    
    startDriver ntp
    ntp_timeZoneOfs 1
    alias plug_on backlog setChannel 1 1
    
    waitFor NTPState 1
    if $hour>=14&&$hour<21 then plug_on
    
    again:
    if $CH2!=0 then do_tick
    delay_s 1
    goto again
    

    Fragment of a table with channel setting options.

    This will make value of channel 5 (inching time) remembered between reboots and settable via Home Assistant.

    Added after 47 [seconds]:

    PS: You will also need to clear the channel type 15 in the Web App, so the second text field diseappers
    Helpful post? Buy me a coffee.
  • #47 20823845
    ciknururko
    Level 3  

    Perfect worked....... Thank you so much for your help and guidance...

    startDriver ntp
    ntp_timeZoneOfs +05:30
    alias plug_on backlog setChannel 1 1
    //addClockEvent 14:36 0xff 1 plug_on

    addClockEvent if $hour>=14&&$hour<21 then 0xff 1 plug_on

    Can we use addClockEvent in the above manner? I mean, is combining IF THEN possible with addClockEvent?

    Kindly reply
  • #48 20823941
    p.kaczmarek2
    Moderator Smart Home
    Currently it's not possible, it's an event, by definition, not a zone.

    Futhermore that would not allow user override of state.

    You should rather do:
    1. at hour 14 do turn on and on hour 21 turn off
    2. alternatively, you can make a loop in autoexec.bat and poll current hour, let's say, every minute, manually, and there put that if condition, this would work, but it would not allow user to override the relay state between 14 and 21

    Do you want user to be able to override the relay state (via WWW panel, HA, or a button) between 14 and 21?
    Helpful post? Buy me a coffee.
  • #49 20825578
    ciknururko
    Level 3  

    No, nothing like that... I was just curious if it can be used in that manner.

    Again, I would really like to thank you for all your help. I really appreciate it.
  • #50 20826035
    p.kaczmarek2
    Moderator Smart Home
    ciknururko wrote:

    No, nothing like that... I was just curious if it can be used in that manner.

    We have considered this in the past, but the problem is, how would we then allow user to "override" the state of the lamp? Maybe we could set a flag to specify whether user is allowed to override it or not...
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #51 20826107
    ciknururko
    Level 3  
    Yes... if possible kindly implement that.
  • #52 20830509
    ciknururko
    Level 3  

    Hi,

    Is there a way to check from HA if an update is available for the plug?
    e.g. For Chipset: BK7231N Build: Build on Nov 13 2023 14:23:53 version 1.17.308 is the latest.

    If there is any OTA available in the future, can we have a sensor in HA that reports that an update is available???

    Secondly, I am having a very peculiar issue. If the plug is powered ON and is detected by HA. After some time, if I restart HA, after the restart the plug is shown as unavailable in HA until I manually toggle it. Any idea why this is happening?

    Kindly reply
  • #53 20830592
    p.kaczmarek2
    Moderator Smart Home
    ciknururko wrote:

    Is there a way to check from HA if an update is available for the plug?
    e.g. For Chipset: BK7231N Build: Build on Nov 13 2023 14:23:53 version 1.17.308 is the latest.

    It is a bit problematic because Github is now HTTPS-only and current version of OBK can't do HTTPS request, only HTTP. Still, why do you want to update that often?


    ciknururko wrote:

    Secondly, I am having a very peculiar issue. If the plug is powered ON and is detected by HA. After some time, if I restart HA, after the restart the plug is shown as unavailable in HA until I manually toggle it. Any idea why this is happening?

    It was discussed here:
    https://www.elektroda.com/rtvforum/topic4001877.html
    I would fix it just by enabling "broadcast self state every N seconds" in flags
    Helpful post? Buy me a coffee.
  • #54 20830622
    ciknururko
    Level 3  

    p.kaczmarek2 wrote:
    It is a bit problematic because GitHub is now HTTPS-only and the current version of OBK can't make HTTPS requests, only HTTP. Still, why do you want to update that often?

    Just wanted to know if it was possible..
    p.kaczmarek2 wrote:
    I would fix it just by enabling "broadcast self state every N seconds" in flags

    Fixed.... thank you
  • #55 20830637
    p.kaczmarek2
    Moderator Smart Home
    That OTA check, would you like it done on HA side, or on OBK side?

    Maybe it would be possible to do a HTTPS query with HA script somehow. And if you want it on OBK side, then we either need to add HTTPS to OBK or create our own simple update HTTP server with public IP.
    Helpful post? Buy me a coffee.
  • #56 20830663
    ciknururko
    Level 3  

    p.kaczmarek2 wrote:
    That OTA check, would you like it done on HA side, or on OBK side?
    HA side
  • #57 20830723
    p.kaczmarek2
    Moderator Smart Home
    Then we would need to port our Javascript getReleases function to HA:
    https://github.com/OpenBekenIOT/webapp/blob/d...a07bdb06175492405e7884e4bf22/vue/ota.vue#L323
    However, I don't think that we can run Javascript in HA. I haven't tried doing that kind of thing yet. Do you know how we could do a HTTPS GET on HA side?
    Helpful post? Buy me a coffee.

Topic summary

The discussion revolves around the Tuya AU LSPA9 Smart Socket, which was successfully flashed with OpenBeken firmware. The main issue addressed is how to turn off the LED indicator on the device when it is powered off. Users explored GPIO extraction to identify the LED control pin and confirmed that the LED is connected to GPIO P8. Solutions were proposed to configure the device to remember its last state after reboot and to implement a countdown timer for automatic shutoff after a specified duration. Users also discussed integrating the device with Home Assistant for remote control and setting inching timers via a GUI. Additionally, there were inquiries about switching between firmware versions and backing up settings.
Summary generated by the language model.
ADVERTISEMENT