Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Controllers
  3. Home Assistant
  4. MySensor on Hass.io - can't get it work

MySensor on Hass.io - can't get it work

Scheduled Pinned Locked Moved Home Assistant
28 Posts 6 Posters 9.9k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MaTyM Offline
    MaTyM Offline
    MaTy
    wrote on last edited by MaTy
    #19

    Yesterday I accidentally restarted Hass.io with all that errors in config. I was afraid that it'll crush after restart but it actually worked. After restart I turned on switch on the wall, and Switch (light relay) appeared on Hass.io home screen.

    There are still the same errors in config, and I have some issues with those light switches. Most annoying issue is that Hass.io doesn't update switch state after change via gui. Switch state changes in Hass.io when i use manual switch on the wall but when I use gui it doesn't
    http://ibb.co/f8Rvum

    martinhjelmareM 1 Reply Last reply
    0
    • MaTyM MaTy

      Yesterday I accidentally restarted Hass.io with all that errors in config. I was afraid that it'll crush after restart but it actually worked. After restart I turned on switch on the wall, and Switch (light relay) appeared on Hass.io home screen.

      There are still the same errors in config, and I have some issues with those light switches. Most annoying issue is that Hass.io doesn't update switch state after change via gui. Switch state changes in Hass.io when i use manual switch on the wall but when I use gui it doesn't
      http://ibb.co/f8Rvum

      martinhjelmareM Offline
      martinhjelmareM Offline
      martinhjelmare
      Plugin Developer
      wrote on last edited by martinhjelmare
      #20

      @maty

      You should send feedback of state changes to home assistant from your device. This is done from the receive function. The switch in home assistant will switch as soon as the feedback comes in.

      Also set optimistic to false in your mysensors config section.

      MaTyM 1 Reply Last reply
      0
      • martinhjelmareM martinhjelmare

        @maty

        You should send feedback of state changes to home assistant from your device. This is done from the receive function. The switch in home assistant will switch as soon as the feedback comes in.

        Also set optimistic to false in your mysensors config section.

        MaTyM Offline
        MaTyM Offline
        MaTy
        wrote on last edited by MaTy
        #21

        @martinhjelmare
        You mean in my sketch, something like this?

        void receive(const MyMessage &message) {
          // We only expect one type of message from controller. But we better check anyway.
          if (message.type==V_LIGHT) {
             // Change relay state
             digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
             // Store state in eeprom
             saveState(message.sensor, message.getBool());
             // Write some debug info
             Serial.print("Incoming change for sensor:");
             Serial.print(message.sensor);
             Serial.print(", New status: ");
             Serial.println(message.getBool());
        

        I had optimistic set false.

        BTW: Strange thing, baud rate in my sketch is 38400, but when I set it up in Hass.io, lights won't work, when I changed to 115200 in .yaml (in sketch is still 38400), all works fine, except the states update.

        martinhjelmareM 1 Reply Last reply
        0
        • MaTyM MaTy

          @martinhjelmare
          You mean in my sketch, something like this?

          void receive(const MyMessage &message) {
            // We only expect one type of message from controller. But we better check anyway.
            if (message.type==V_LIGHT) {
               // Change relay state
               digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
               // Store state in eeprom
               saveState(message.sensor, message.getBool());
               // Write some debug info
               Serial.print("Incoming change for sensor:");
               Serial.print(message.sensor);
               Serial.print(", New status: ");
               Serial.println(message.getBool());
          

          I had optimistic set false.

          BTW: Strange thing, baud rate in my sketch is 38400, but when I set it up in Hass.io, lights won't work, when I changed to 115200 in .yaml (in sketch is still 38400), all works fine, except the states update.

          martinhjelmareM Offline
          martinhjelmareM Offline
          martinhjelmare
          Plugin Developer
          wrote on last edited by
          #22

          @maty

          In your example above you never send the feedback from receive. Use the send method
          from within receive to do that.

          In what sketch have you set baud rate to 38400? For the light device or for the gateway? It's only the gateway baud rate that is relevant for home assistant config, since it's the gateway that interfaces via the serial connection to home assistant.

          MaTyM 1 Reply Last reply
          0
          • martinhjelmareM martinhjelmare

            @maty

            In your example above you never send the feedback from receive. Use the send method
            from within receive to do that.

            In what sketch have you set baud rate to 38400? For the light device or for the gateway? It's only the gateway baud rate that is relevant for home assistant config, since it's the gateway that interfaces via the serial connection to home assistant.

            MaTyM Offline
            MaTyM Offline
            MaTy
            wrote on last edited by MaTy
            #23

            @martinhjelmare

            Should it be something like this added to my sketch?

            send(msg.set(RELAY_1;V_LIGHT)
            send(msg.set(RELAY_2;V_LIGHT)
            ...
            

            I ment BAUD_RATE defined in this sketch

            #if F_CPU == 8000000L
            #define MY_BAUD_RATE 38400
            #endif
            

            Once again, sorry for tons of noob questions. But I didn't write that sketch by myself, and my knowledge about programming is below basic.

            1 Reply Last reply
            0
            • martinhjelmareM Offline
              martinhjelmareM Offline
              martinhjelmare
              Plugin Developer
              wrote on last edited by
              #24

              Something like this:

              send(msg.set(state));
              

              The arduino mega runs at 16 MHz so that if block won't be entered, and the define of baud rate won't change.

              MaTyM 1 Reply Last reply
              0
              • martinhjelmareM martinhjelmare

                Something like this:

                send(msg.set(state));
                

                The arduino mega runs at 16 MHz so that if block won't be entered, and the define of baud rate won't change.

                MaTyM Offline
                MaTyM Offline
                MaTy
                wrote on last edited by
                #25

                @martinhjelmare

                Hi,
                I checked my sketch once again, and confronted it with MySensors documentation, and I actually found the send message command in it. Should I change something to make it work properly with Hass.io

                void loop() {
                  // Send locally attached sensor data here
                  if (debouncer.update()) {
                    // Get the update value.
                    int value = debouncer.read();
                    // Send in the new value.
                    if(value == LOW){
                         saveState(1, !loadState(1));
                         digitalWrite(RELAY_1, loadState(1)?RELAY_ON:RELAY_OFF);
                         send(msg.set(loadState(1)));
                
                martinhjelmareM 1 Reply Last reply
                0
                • MaTyM MaTy

                  @martinhjelmare

                  Hi,
                  I checked my sketch once again, and confronted it with MySensors documentation, and I actually found the send message command in it. Should I change something to make it work properly with Hass.io

                  void loop() {
                    // Send locally attached sensor data here
                    if (debouncer.update()) {
                      // Get the update value.
                      int value = debouncer.read();
                      // Send in the new value.
                      if(value == LOW){
                           saveState(1, !loadState(1));
                           digitalWrite(RELAY_1, loadState(1)?RELAY_ON:RELAY_OFF);
                           send(msg.set(loadState(1)));
                  
                  martinhjelmareM Offline
                  martinhjelmareM Offline
                  martinhjelmare
                  Plugin Developer
                  wrote on last edited by martinhjelmare
                  #26

                  @maty

                  Yes. There are two ways of interacting with the device to make a state change. Either by pressing the button or by sending a message from home assistant to the device. The send command you showed above will only happen if the button is pressed when the loop is running.

                  When you send a message from home assistant to the device, to change the state, the message will be received in your sketch by the receive function.

                  So you need to add a send command to the receive function and send the new state back to home assistant after doing the digitalWrite call and saving the state.

                  1 Reply Last reply
                  0
                  • MaTyM MaTy

                    @tom-carpenter
                    How did You make it? Is it via serial gateway?

                    Tom CarpenterT Offline
                    Tom CarpenterT Offline
                    Tom Carpenter
                    wrote on last edited by
                    #27

                    @maty Yes serial gateway hooked to the pi

                    R 1 Reply Last reply
                    0
                    • Tom CarpenterT Tom Carpenter

                      @maty Yes serial gateway hooked to the pi

                      R Offline
                      R Offline
                      Rincewind
                      wrote on last edited by
                      #28

                      @tom-carpenter How did you configure the serial gateway in configuration.yaml? can you please post that section?

                      Also what arduino hardware did you use?

                      Thanks

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      15

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.1k

                      Posts


                      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular