https://toitlang.org/ logo
Join Discord
Powered by
# show-and-tell
  • a

    Arubinu

    05/02/2025, 10:24 AM
    Please be kind—this is my first Toit.io project, but I’m open to all feedback 🙂 This project allows you to control various Zigbee bulbs via Zigbee2MQTT. To do so, you’ll need a switch like the one I’m using (IKEA STYRBAR) or another that works similarly. I’ve also added control for Elgato LED panels and WiZ bulbs (both of which use Wi-Fi). Everything else should be briefly explained in the README. Hope this source code gives you some inspiration! https://github.com/Arubinu/mqtt-automations
  • f

    floitsch

    05/15/2025, 7:32 AM
    Nice. Instead of having the configurations and credentials hard-coded, you could use https://pkg.toit.io/package/github.com%2Ffloitsch%2Ftoit-simple-config. I wrote that package for a similar use-case. Also: you probably have enough memory left to add a telegram bot to the device (https://pkg.toit.io/package/github.com%2Ffloitsch%2Ftoit-telegram). I always find it nice when I can control (or monitor) my devices over the phone, and Telegram has the easiest way to set up bots.
  • f

    floitsch

    05/15/2025, 7:34 AM
    Minor feedback on the code: looks generally good and Toity. I did notice two things, though: The toitdocs aren't following the toitdoc conventions. If you do a
    toit toitdoc serve
    it will probably not render correctly. You generally use
    this.foo
    to access instance fields. That's not necessary (assuming there is no name-collision): just
    foo
    works as well.
  • a

    Arubinu

    05/15/2025, 9:29 PM
    toit-simple-config
    is really interesting — I was actually looking for a way to separate credentials from the code, so thank you for that. Regarding Telegram, I actually have very limited network access, but I understand its usefulness. My main control center is Home Assistant, and I was hoping to use MQTT Discovery so my home automation setup could detect this new device automatically. But I haven’t managed to get that working properly yet (it’s kind of depressing). You're right about this.foo — it’s unnecessary in many languages. But I figured it would improve readability by making it obvious at a glance that the variable comes from the instance itself. On the other hand, I haven’t been able to try
    toit toitdoc serve
    since my only access is through
    jag
    . I could easily find where the toit executable is and add it to the PATH, but I don’t really feel comfortable adding a whole paragraph about that to the GitHub project just so other users can get
    toit-simple-config
    working.
  • k

    kaxori

    05/22/2025, 4:39 PM
    If you are still struggling with device discovery - you can have a look to this example: https://github.com/kaxori/Example-Device-Discovery
  • a

    Arubinu

    05/23/2025, 8:09 PM
    Thank you for this example. I’ve adapted the code in my own way for my project, but I don’t understand why Home Assistant doesn’t mark the sensors as “unavailable” when one (or both) of the "availability" topics change to “offline”... Do you have any idea what might be causing this? Don't pay attention to the "online" value in the screenshot, my test did correctly show "offline" until I reconnected the ESP32.
  • a

    Arubinu

    05/23/2025, 8:11 PM
    https://cdn.discordapp.com/attachments/1367748896633262131/1375566776363909160/image.png?ex=683227e4&is=6830d664&hm=fcf691fde7a677066a78377c82722793c5167af8c8a3f118aa383590b2ef4fd5&
  • k

    kaxori

    05/24/2025, 7:30 AM
    Hi Arubino, example button-counter: - create entity:
    Copy code
    hass.create-sensor-entity --data-label="button" --data-category="measure"
        --device-class=""
        --data-unit="#"
    - set value:
    Copy code
    publish-mqtt "?measure/button" "$(%d button-counter)"
    - message data in MQTT explorer: - published: manually set RAW value ! - received: ? hope it helps ...?
  • k

    kaxori

    05/24/2025, 7:41 AM
    https://cdn.discordapp.com/attachments/1367748896633262131/1375740578771370035/2025-05-24_09h34_17.png?ex=6832c9c2&is=68317842&hm=2808e3e8be1652be3ff53526198b4fbc6e798ae0a7f3ef6506584c67117ac3a3& https://cdn.discordapp.com/attachments/1367748896633262131/1375740578976764015/image.png?ex=6832c9c2&is=68317842&hm=b63d2bfae9bea4b40fa7d20626fd9adc3a7e71754de52d8d4154001d15ae999f& https://cdn.discordapp.com/attachments/1367748896633262131/1375740579224359042/image.png?ex=6832c9c2&is=68317842&hm=29c95d0f6260e8086a1445ce1ecb98763682259fa3fb81d9224484808a2a36c9&
  • a

    Arubinu

    05/24/2025, 11:26 AM
    I understood how all this worked. It's mainly the
    /availability
    containing
    {"state":"offline"}
    that is not taken into account even though I have the following in `/config`:
    Copy code
    json
    "availability_mode": "all",
    "availability_topic": [
      {
        "topic": "toit/64e8338a3e1c/state",
        "value_template": "{{ value_json.state }}"
      },
      {
        "topic": "toit/64e8338a3e1c/binary_sensor/low-battery/availability",
        "value_template": "{{ value_json.state }}"
      }
    ]
  • k

    kaxori

    05/24/2025, 1:10 PM
    May be you have to define a suited "last will" message that is sent by the broker if the device is offline.
  • a

    Arubinu

    05/24/2025, 7:35 PM
    I do it and it goes fine to "offline" but Home Assistant doesn't put them in "unavailable".
  • b

    bpmct

    05/25/2025, 12:31 AM
    This is a project I have been working on for a while, thanks to Toit making the development and fleet management so easy. I am sending a batch to friends/family now 🙂 https://cdn.discordapp.com/attachments/1367748896633262131/1375994581568716930/tio.MOV?ex=6833b650&is=683264d0&hm=2aaadd3629cd542d5809ca682c44be4818310492230119eaa18f8f1d342ae37f&
  • k

    kasperl

    05/25/2025, 5:51 AM
    That looks incredibly cool 😎
  • k

    kaxori

    06/03/2025, 6:02 PM
    My way to implement the availability:
    Copy code
    // setup a cyclic heartbeat task
      heartbeat-task = task :: heart-beat_ 
    
      heart-beat_ :
        publish-mqtt "$(TOPIC-AVAILABILITY-BASE)" "online" --retain
        sleep --ms=HEARTBEAT-INTERVAL
    
      ...
    
    
      // add this to component definition
      ...
      "expire_after": 90,
      "availability": {
        "topic":  "$(TOPIC-AVAILABILITY-BASE)",   
        "payload_available": "online",
        "payload_not_available": "offline"
      },
    ... hope, this will help you ...
  • a

    Arubinu

    06/03/2025, 6:04 PM
    I will test it later, thank you very much
  • k

    kaxori

    06/03/2025, 6:16 PM
    🥳 Solution delivered by **claude.ai **(after @floitsch mentioned that LLM) 🤩
  • d

    davidg238

    06/28/2025, 1:42 AM
    what started as an experiment with
    write-on-stdout_
    turned into an exercise with coding assistants. You can see the logs here https://github.com/davidg238/fft , resulting in
    jag run -d host sample.toit
  • f

    floitsch

    06/28/2025, 10:06 AM
    very nice.