Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Damian Chojna
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Damian Chojna

    @Damian Chojna

    1
    Reputation
    3
    Posts
    1
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Damian Chojna Follow

    Best posts made by Damian Chojna

    • TypeError: '<' not supported between instances of 'str' and 'int'

      The problem
      TypeError: '<' not supported between instances of 'str' and 'int'
      When receive messages like 0;2;1;0;2;1

      Environment
      raspberry v4
      arduino mega with lib mysensors 2.3 connected with USB to raspberry:

      Home Assistant release (hass --version):
      0.104.3

      Python release (python3 --version):
      3.7.6

      HomeAssistant Logs:

      2020-01-30 12:45:06 DEBUG (MainThread) [mysensors] Receiving 0;2;1;0;2;1
      2020-01-30 12:45:06 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback SerialTransport._read_ready()
      Traceback (most recent call last):
        File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
          self._context.run(self._callback, *self._args)
        File "/usr/local/lib/python3.7/site-packages/serial_asyncio/__init__.py", line 106, in _read_ready
          self._protocol.data_received(data)
        File "/usr/local/lib/python3.7/site-packages/serial/threaded/__init__.py", line 65, in data_received
          self.handle_packet(packet)
        File "/usr/local/lib/python3.7/site-packages/serial/threaded/__init__.py", line 132, in handle_packet
          self.handle_line(packet.decode(self.ENCODING, self.UNICODE_HANDLING))
        File "/usr/local/lib/python3.7/site-packages/mysensors/__init__.py", line 437, in handle_line
          self.gateway.add_job(self.gateway.logic, line)
        File "/usr/local/lib/python3.7/site-packages/mysensors/__init__.py", line 375, in add_job
          reply = self.run_job(job)
        File "/usr/local/lib/python3.7/site-packages/mysensors/__init__.py", line 151, in run_job
          reply = func(*args)
        File "/usr/local/lib/python3.7/site-packages/mysensors/__init__.py", line 72, in logic
          ret = handler(msg)
        File "/usr/local/lib/python3.7/site-packages/mysensors/handler.py", line 64, in handle_set
          msg.child_id, msg.sub_type, msg.payload)
        File "/usr/local/lib/python3.7/site-packages/mysensors/sensor.py", line 123, in set_child_value
          msg.validate(self.protocol_version)
        File "/usr/local/lib/python3.7/site-packages/mysensors/message.py", line 78, in validate
          const = get_const(protocol_version)
        File "/usr/local/lib/python3.7/site-packages/mysensors/const.py", line 25, in get_const
          ), 'mysensors.const_14')
      TypeError: '<' not supported between instances of 'str' and 'int'
      

      Arduino code:

      // Enable debug prints to serial monitor
      //#define MY_DEBUG 
      
      
      // Enable and select radio type attached
      //#define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Set LOW transmit power level as default, if you have an amplified NRF-module and
      // power your radio separately with a good regulator you can turn up PA level. 
      //#define MY_RF24_PA_LEVEL RF24_PA_LOW
      
      // Enable serial gateway
      #define MY_GATEWAY_SERIAL
      
      // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
      #if F_CPU == 8000000L
      #define MY_BAUD_RATE 38400
      #endif
      
      // Flash leds on rx/tx/err
      // #define MY_LEDS_BLINKING_FEATURE
      // Set blinking period
      // #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Inverses the behavior of leds
      // #define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      #define MY_INCLUSION_BUTTON_FEATURE
      
      // Inverses behavior of inclusion button (if using external pullup)
      //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
      
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60 
      // Digital pin used for inclusion mode button
      #define MY_INCLUSION_MODE_BUTTON_PIN  3 
      
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
      
      #include <SPI.h>
      #include <MySensors.h>  
      #include <Bounce2.h>
      
      // Enable repeater functionality for this node
      #define MY_REPEATER_FEATURE
      
      
      #define RELAY_1  4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define RELAY_2  5
      #define NUMBER_OF_RELAYS 2 // Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      
      #define BUTTON_PIN A1
      #define BUTTON2_PIN A2
      
      
      void before() { 
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);   
          // Set relay to last known state (using eeprom storage) 
          digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
      }
      Bounce debouncer = Bounce();
      Bounce debouncer2 = Bounce();
      
      void setup() { 
        // Setup locally attached sensors
        delay(10000);
         // Setup the button.
        pinMode(BUTTON_PIN, INPUT_PULLUP);
        pinMode(BUTTON2_PIN, INPUT_PULLUP);
        // After setting up the button, setup debouncer.
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(5);
        debouncer2.attach(BUTTON2_PIN);
        debouncer2.interval(5);
      
        //presentation();
      }
      void presentation()  
      {   
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay", "1.0");
      
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Register all sensors to gw (they will be created as child devices)
          present(sensor, S_BINARY);
        }
      }
      
      MyMessage msg(1, V_STATUS);
      MyMessage msg2(2, V_STATUS);
      
      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)));
               }
        }
        if (debouncer2.update()) {
            int value2 = debouncer2.read();
          if(value2 == LOW){
               saveState(2, !loadState(2));
               digitalWrite(RELAY_2, loadState(2)?RELAY_ON:RELAY_OFF);
               send(msg2.set(loadState(2)));
               }
        }
      }
      
      
      void receive(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_STATUS) {
           // 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());
         } 
      }
      
      posted in Home Assistant
      Damian Chojna
      Damian Chojna

    Latest posts made by Damian Chojna

    • Truncated message when arduino sending version info:

      I check that in mMySensors arduino lib 2.3.2 on ArduinoMega

      Problem with the cut message when arduino send version info:

      0;255;0;0;17;2 /*!< Major release vers
      

      In Arduino/libraries/MySensors/core/Version.h, in MYSENSORS_LIBRARY_VERSION_MINOR is this cut off message. This makes mysensors in the home assistant not work.

      Line 58:

      #define MYSENSORS_LIBRARY_VERSION STR(MYSENSORS_LIBRARY_VERSION_MAJOR) "." STR(MYSENSORS_LIBRARY_VERSION_MINOR) "." STR(MYSENSORS_LIBRARY_VERSION_PATCH) //!< final release versioning
      

      When I replace it with, this work for me.

      MYSENSORS_LIBRARY_VERSION "2.3.2"
      

      Is this correct behavior ?

      Arduino Code:

      #define MY_GATEWAY_SERIAL
      #define MY_REPEATER_FEATURE
      #define MY_NODE_ID 0
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      
      #define RELAY_PIN  5
      #define BUTTON_PIN  A0
      #define CHILD_ID 1
      #define RELAY_ON 1
      #define RELAY_OFF 0
      
      Bounce debouncer = Bounce();
      bool state = false;
      bool initialValueSent = false;
      
      MyMessage msg(CHILD_ID, V_STATUS);
      
      void setup()
      {
        pinMode(BUTTON_PIN, INPUT_PULLUP);
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(10);
      
        // Make sure relays are off when starting up
        digitalWrite(RELAY_PIN, RELAY_OFF);
        pinMode(RELAY_PIN, OUTPUT);
      }
      
      void presentation()  {
        sendSketchInfo("Relay+button", "1.0");
        present(CHILD_ID, S_BINARY);
      }
      
      void loop()
      {
        if (!initialValueSent) {
          Serial.println("Sending initial value");
          send(msg.set(state?RELAY_ON:RELAY_OFF));
          Serial.println("Requesting initial value from controller");
          request(CHILD_ID, V_STATUS);
          wait(2000, C_SET, V_STATUS);
        }
        if (debouncer.update()) {
          if (debouncer.read()==LOW) {
            state = !state;
            // Send new state and request ack back
            send(msg.set(state?RELAY_ON:RELAY_OFF), true);
          }
        }
      }
      
      void receive(const MyMessage &message) {
        if (message.isAck()) {
           Serial.println("This is an ack from gateway");
        }
      
        if (message.type == V_STATUS) {
          if (!initialValueSent) {
            Serial.println("Receiving initial value from controller");
            initialValueSent = true;
          }
          // Change relay state
          state = (bool)message.getInt();
          digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
          send(msg.set(state?RELAY_ON:RELAY_OFF));
        }
      }
      

      Serial Output:

      0;255;3;0;14;Gateway startup complete.
      0;255;0;0;17;2 /*!< Major release vers
      0;255;3;0;11;Relay+button
      0;255;3;0;12;1.0
      0;1;0;0;3;
      
      posted in Troubleshooting
      Damian Chojna
      Damian Chojna
    • RE: TypeError: '<' not supported between instances of 'str' and 'int'

      @skywatch it's not me trying to compare, it happens in the mysensors library when receiving messages. It seems that mysensors is badly implemented in the home assistant, in domoticz it works very well

      posted in Home Assistant
      Damian Chojna
      Damian Chojna
    • TypeError: '<' not supported between instances of 'str' and 'int'

      The problem
      TypeError: '<' not supported between instances of 'str' and 'int'
      When receive messages like 0;2;1;0;2;1

      Environment
      raspberry v4
      arduino mega with lib mysensors 2.3 connected with USB to raspberry:

      Home Assistant release (hass --version):
      0.104.3

      Python release (python3 --version):
      3.7.6

      HomeAssistant Logs:

      2020-01-30 12:45:06 DEBUG (MainThread) [mysensors] Receiving 0;2;1;0;2;1
      2020-01-30 12:45:06 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback SerialTransport._read_ready()
      Traceback (most recent call last):
        File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
          self._context.run(self._callback, *self._args)
        File "/usr/local/lib/python3.7/site-packages/serial_asyncio/__init__.py", line 106, in _read_ready
          self._protocol.data_received(data)
        File "/usr/local/lib/python3.7/site-packages/serial/threaded/__init__.py", line 65, in data_received
          self.handle_packet(packet)
        File "/usr/local/lib/python3.7/site-packages/serial/threaded/__init__.py", line 132, in handle_packet
          self.handle_line(packet.decode(self.ENCODING, self.UNICODE_HANDLING))
        File "/usr/local/lib/python3.7/site-packages/mysensors/__init__.py", line 437, in handle_line
          self.gateway.add_job(self.gateway.logic, line)
        File "/usr/local/lib/python3.7/site-packages/mysensors/__init__.py", line 375, in add_job
          reply = self.run_job(job)
        File "/usr/local/lib/python3.7/site-packages/mysensors/__init__.py", line 151, in run_job
          reply = func(*args)
        File "/usr/local/lib/python3.7/site-packages/mysensors/__init__.py", line 72, in logic
          ret = handler(msg)
        File "/usr/local/lib/python3.7/site-packages/mysensors/handler.py", line 64, in handle_set
          msg.child_id, msg.sub_type, msg.payload)
        File "/usr/local/lib/python3.7/site-packages/mysensors/sensor.py", line 123, in set_child_value
          msg.validate(self.protocol_version)
        File "/usr/local/lib/python3.7/site-packages/mysensors/message.py", line 78, in validate
          const = get_const(protocol_version)
        File "/usr/local/lib/python3.7/site-packages/mysensors/const.py", line 25, in get_const
          ), 'mysensors.const_14')
      TypeError: '<' not supported between instances of 'str' and 'int'
      

      Arduino code:

      // Enable debug prints to serial monitor
      //#define MY_DEBUG 
      
      
      // Enable and select radio type attached
      //#define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Set LOW transmit power level as default, if you have an amplified NRF-module and
      // power your radio separately with a good regulator you can turn up PA level. 
      //#define MY_RF24_PA_LEVEL RF24_PA_LOW
      
      // Enable serial gateway
      #define MY_GATEWAY_SERIAL
      
      // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
      #if F_CPU == 8000000L
      #define MY_BAUD_RATE 38400
      #endif
      
      // Flash leds on rx/tx/err
      // #define MY_LEDS_BLINKING_FEATURE
      // Set blinking period
      // #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Inverses the behavior of leds
      // #define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      #define MY_INCLUSION_BUTTON_FEATURE
      
      // Inverses behavior of inclusion button (if using external pullup)
      //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
      
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60 
      // Digital pin used for inclusion mode button
      #define MY_INCLUSION_MODE_BUTTON_PIN  3 
      
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
      
      #include <SPI.h>
      #include <MySensors.h>  
      #include <Bounce2.h>
      
      // Enable repeater functionality for this node
      #define MY_REPEATER_FEATURE
      
      
      #define RELAY_1  4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define RELAY_2  5
      #define NUMBER_OF_RELAYS 2 // Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      
      #define BUTTON_PIN A1
      #define BUTTON2_PIN A2
      
      
      void before() { 
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);   
          // Set relay to last known state (using eeprom storage) 
          digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
      }
      Bounce debouncer = Bounce();
      Bounce debouncer2 = Bounce();
      
      void setup() { 
        // Setup locally attached sensors
        delay(10000);
         // Setup the button.
        pinMode(BUTTON_PIN, INPUT_PULLUP);
        pinMode(BUTTON2_PIN, INPUT_PULLUP);
        // After setting up the button, setup debouncer.
        debouncer.attach(BUTTON_PIN);
        debouncer.interval(5);
        debouncer2.attach(BUTTON2_PIN);
        debouncer2.interval(5);
      
        //presentation();
      }
      void presentation()  
      {   
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay", "1.0");
      
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Register all sensors to gw (they will be created as child devices)
          present(sensor, S_BINARY);
        }
      }
      
      MyMessage msg(1, V_STATUS);
      MyMessage msg2(2, V_STATUS);
      
      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)));
               }
        }
        if (debouncer2.update()) {
            int value2 = debouncer2.read();
          if(value2 == LOW){
               saveState(2, !loadState(2));
               digitalWrite(RELAY_2, loadState(2)?RELAY_ON:RELAY_OFF);
               send(msg2.set(loadState(2)));
               }
        }
      }
      
      
      void receive(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_STATUS) {
           // 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());
         } 
      }
      
      posted in Home Assistant
      Damian Chojna
      Damian Chojna