logo elektroda
logo elektroda
X
logo elektroda

Access to Mqtt channel from the autoexec of openBK - example required

housertelmstein 1260 2
ADVERTISEMENT
Treść została przetłumaczona german » english Zobacz oryginalną wersję tematu
  • #1 20721401
    housertelmstein
    Level 3  
    Hi,

    Can I access an MQTT channel from the autoexec of OpenBK? I think it works with $CH***, right?
    But somehow it doesn't work. Can someone make me a small example?

    Thanks and greetings

    Silas
  • ADVERTISEMENT
  • #2 20721851
    p.kaczmarek2
    Moderator Smart Home
    Indeed, in OpenBeken it is possible to access variables in commands via the relevant keywords:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/constants.md
    This means that, for example, the script:
    
    setChannel 10 123
    publishInt MyVar $CH10*0.1
    

    publishes via MQTT the MyVar key and the value 12.3, i.e. the value of channel 10 multiplied by 0.1.


    The specific script and use of variables depends on what you are trying to do. So can you describe what effect you want to achieve and provide the code you are working on now?
    Helpful post? Buy me a coffee.
  • #3 20721903
    housertelmstein
    Level 3  
    Hi

    Thanks for the answer. I need it the other way round.
    I would like to read out time in sec from a mqtt channel.
    For example, I have a slider in Home Assistant. For example, I have a slider in Home Assistant with which you can select a number between 0 and 25. This is then published via mqtt (shutter/Kirchen/4).
    Now I would like to read the value from shutter/Kirchen/4 when calling the script to open the shutter and set it as delay_s.

    I thought it would work like this:
    
    setChannel 1 1
    delay_s $CH4
    setChannel 1 0
    


    But $CH*** only refers to the channel of the device, right?

    Added after 9 [hours] 10 [minutes]:

    I figured it out!
    To publish from autoexec as usual with:

    publish #TOPIC# Value


    e. e.g.: publish TestTopic 55

    then the topic TestTopic is "created" in Mqtt under the respective device and the value 55 is "saved" under TestTopic/get

    If you now want to write values from Homeassistant, for example, and want to read them later in the Autoexec, you can do this as follows:
    e.g. with a slider an input for the device. For example, change an InputNumber with a slider and then publish to TestTopic/set using script or automation in Mqtt!
    It is important to publish to /set! Then you can access the value from the autoexec with $CHTestTopic!
    I hope it is somewhat understandable. As soon as I'm finished, I'll post the complete code!

    Greetings Silas
ADVERTISEMENT