HA: moisture sensor ValueError: could not convert string to float: '2.1.1'



  • I am attempting to incorporate a moisture sensor into HA but getting could not convert to float errors in the logs. The sensor does show up in mysensors.json but not in the gui.

    Home Assistant 0.94.4

    I am using a simple FC-28 moisture sensor: VCC, Gnd, D0 connected to D6 of the UNO and A0 connected to D7.

    SoilMoistSensor Sketch:

    /*
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2018 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * DESCRIPTION
     *
     * Arduino soil moisture based on gypsum sensor/resistive sensor to avoid electric catalyse in soil
     *  Required to interface the sensor: 2 * 4.7kOhm + 2 * 1N4148
     *
     * Gypsum sensor and calibration:
     *	DIY: See http://vanderleevineyard.com/1/category/vinduino/1.html
     *	Built: Davis / Watermark 200SS
     *		http://www.cooking-hacks.com/watermark-soil-moisture-sensor?_bksrc=item2item&_bkloc=product
     *		http://www.irrometer.com/pdf/supportmaterial/sensors/voltage-WM-chart.pdf
     *		cb (centibar) http://www.irrometer.com/basics.html
     *			0-10 Saturated Soil. Occurs for a day or two after irrigation
     *			10-20 Soil is adequately wet (except coarse sands which are drying out at this range)
     *			30-60 Usual range to irrigate or water (except heavy clay soils).
     *			60-100 Usual range to irrigate heavy clay soils
     *			100-200 Soil is becoming dangerously dry for maximum production. Proceed with caution.
     *
     * Connection:
     * D6, D7: alternative powering to avoid sensor degradation
     * A0, A1: alternative resistance measuring
     *
     *  Based on:
     *  "Vinduino" portable soil moisture sensor code V3.00
     *   Date December 31, 2012
     *   Reinier van der Lee and Theodore Kaskalis
     *   www.vanderleevineyard.com
     * Contributor: epierre
     */
    
    // Copyright (C) 2015, Reinier van der Lee
    // www.vanderleevineyard.com
    
    // This program is free software: you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation, either version 3 of the License, or
    // any later version.
    
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #include <math.h>       // Conversion equation from resistance to %
    #include <MySensors.h>
    
    // Setting up format for reading 3 soil sensors
    #define NUM_READS (int)10    // Number of sensor reads for filtering
    #define CHILD_ID 0
    
    MyMessage msg(CHILD_ID, V_LEVEL);
    uint32_t SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    long buffer[NUM_READS];
    int idx;
    
    /// @brief Structure to be used in percentage and resistance values matrix to be filtered (have to be in pairs)
    typedef struct {
    	int moisture; //!< Moisture
    	long resistance; //!< Resistance
    } values;
    
    const long knownResistor = 4700;  // Constant value of known resistor in Ohms
    
    int supplyVoltage;                // Measured supply voltage
    int sensorVoltage;                // Measured sensor voltage
    
    values valueOf[NUM_READS];        // Calculated moisture percentages and resistances to be sorted and filtered
    
    int i;                            // Simple index variable
    
    void setup()
    {
    	// initialize the digital pins as an output.
    	// Pin 6,7 is for sensor 1
    	// initialize the digital pin as an output.
    	// Pin 6 is sense resistor voltage supply 1
    	pinMode(6, OUTPUT);
    
    	// initialize the digital pin as an output.
    	// Pin 7 is sense resistor voltage supply 2
    	pinMode(7, OUTPUT);
    }
    
    void presentation()
    {
    	sendSketchInfo("Soil Moisture Sensor Reverse Polarity", "1.0");
    	present(CHILD_ID, S_MOISTURE);
    }
    
    void loop()
    {
    
    	measure(6,7,1);
    	Serial.print ("\t");
    	Serial.println (average());
    	long read1 = average();
    
    	measure(7,6,0);
    	Serial.print ("\t");
    	Serial.println (average());
    	long read2= average();
    
    	long sensor1 = (read1 + read2)/2;
    
    	Serial.print ("resistance bias =" );
    	Serial.println (read1-read2);
    	Serial.print ("sensor bias compensated value = ");
    	Serial.println (sensor1);
    	Serial.println ();
    
    	//send back the values
    	send(msg.set((int32_t)ceil(sensor1)));
    	// delay until next measurement (msec)
    	sleep(SLEEP_TIME);
    }
    
    
    
    void measure (int phase_b, int phase_a, int analog_input)
    {
    	// read sensor, filter, and calculate resistance value
    	// Noise filter: median filter
    
    	for (i=0; i<NUM_READS; i++) {
    
    		// Read 1 pair of voltage values
    		digitalWrite(phase_a, HIGH);                 // set the voltage supply on
    		delayMicroseconds(25);
    		supplyVoltage = analogRead(analog_input);   // read the supply voltage
    		delayMicroseconds(25);
    		digitalWrite(phase_a, LOW);                  // set the voltage supply off
    		delay(1);
    
    		digitalWrite(phase_b, HIGH);                 // set the voltage supply on
    		delayMicroseconds(25);
    		sensorVoltage = analogRead(analog_input);   // read the sensor voltage
    		delayMicroseconds(25);
    		digitalWrite(phase_b, LOW);                  // set the voltage supply off
    
    		// Calculate resistance
    		// the 0.5 add-term is used to round to the nearest integer
    		// Tip: no need to transform 0-1023 voltage value to 0-5 range, due to following fraction
    		long resistance = (knownResistor * (supplyVoltage - sensorVoltage ) / sensorVoltage) ;
    
    		delay(1);
    		addReading(resistance);
    		Serial.print (resistance);
    		Serial.print ("\t");
    	}
    }
    

    Arduino Serial Monitor:

    11679 TSF:MSG:SEND,105-105-0-0,s=0,c=1,t=37,pt=4,l=4,sg=0,ft=0,st=OK:2
    11687 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    11693 TSF:TDI:TSL
    11695 MCO:SLP:WUP=-1
    11697 TSF:TRI:TSB
    34	11	0	-11	0	11	23	23	11	0		10
    -21	-10	10	11	0	-11	-22	-11	-10	11		-5
    resistance bias =15
    sensor bias compensated value = 2
    
    11756 TSF:MSG:SEND,105-105-0-0,s=0,c=1,t=37,pt=4,l=4,sg=0,ft=0,st=OK:2
    11765 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    11770 TSF:TDI:TSL
    11772 MCO:SLP:WUP=-1
    11773 TSF:TRI:TSB
    11	22	23	11	-11	-11	0	11	23	11		9
    -11	-11	-11	0	11	11	0	-11	-22	-11		-5
    resistance bias =14
    sensor bias compensated value = 2
    
    11833 TSF:MSG:SEND,105-105-0-0,s=0,c=1,t=37,pt=4,l=4,sg=0,ft=0,st=OK:2
    11842 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    11847 TSF:TDI:TSL
    11849 MCO:SLP:WUP=-1
    11851 TSF:TRI:TSB
    23	0	0	-11	11	23	23	23	0	-11		8
    -10	0	10	22	0	-22	-22	-10	11	11		-1
    resistance bias =9
    sensor bias compensated value = 3
    
    11911 TSF:MSG:SEND,105-105-0-0,s=0,c=1,t=37,pt=4,l=4,sg=0,ft=0,st=OK:3
    11919 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    11924 TSF:TDI:TSL
    // Averaging algorithm
    void addReading(long resistance)
    {
    	buffer[idx] = resistance;
    	idx++;
    	if (idx >= NUM_READS) {
    		idx = 0;
    	}
    }
    
    long average()
    {
    	long sum = 0;
    	for (int i = 0; i < NUM_READS; i++) {
    		sum += buffer[i];
    	}
    	return (long)(sum / NUM_READS);
    }
    

    Mysensors.json Moisture Sensor:
    "105": {
    "sensor_id": 105,
    "children": {
    "0": {
    "id": 0,
    "type": 35,
    "description": "",
    "values": {
    "37": "3"
    }
    }
    },
    "type": 17,
    "sketch_name": "Soil Moisture Sensor Reve",
    "sketch_version": "1.0",
    "battery_level": 0,
    "protocol_version": "2.3.1",
    "heartbeat": 0
    }

    HA Logs:

    ValueError: could not convert string to float: '2.1.1'
    2019-07-03 12:35:20 DEBUG (SyncWorker_2) [mysensors.persistence] Saving sensors to persistence file /home/homeassistant/.homeassistant/mysensors.json
    2019-07-03 12:35:47 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:TSF:MSG:READ,105-105-0,s=0,c=1,t=37,pt=4,l=4,sg=0:1
    2019-07-03 12:35:47 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 105 child 0
    2019-07-03 12:35:47 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: Soil Moisture Sensor Reve 105 0: value_type 37, value = 1
    2019-07-03 12:35:47 ERROR (MainThread) [homeassistant.components.mysensors.device] Error updating Soil Moisture Sensor Reve 105 0
    Traceback (most recent call last):
      File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/mysensors/device.py", line 103, in update
        await self._async_update_callback()
      File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/mysensors/device.py", line 129, in _async_update_callback
        await self.async_update_ha_state(True)
      File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
        self._async_write_ha_state()
      File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 258, in _async_write_ha_state
        unit_of_measurement = self.unit_of_measurement
      File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/mysensors/sensor.py", line 75, in unit_of_measurement
        if (float(self.gateway.protocol_version) >= 1.5
    ValueError: could not convert string to float: '2.1.1'
    2019-07-03 12:35:50 DEBUG (SyncWorker_8) [mysensors.persistence] Saving sensors to persistence file /home/homeassistant/.homeassistant/mysensors.json
    


  • @mrhutchinsonmn I am revisiting this issue, attempting to get a mysensors wifi moisture sensor device working in my Homeassistant install. No one from my sensors or homeassistant was able to assist when I first created this topic. The setup and errors are the same. I am hoping someone has learned what the issue is that is causing the error and preventing the moisture sensor from appearing in the homeassistant gui. I am open to a different approach, if there is a better solution.


  • Hardware Contributor

    @mrhutchinsonmn - values in mysensors json looks very strange.

    "values": {
    "37": "3"
    }
    

    Not sure what else. did you try to stop HA and remove the node from mysensors json and preesnt it again?



  • Yes, I removed mysensors.json and restarted. I just finished doing a new install of HA in case it was simply a version issue. I have more info now from the logs. What do you make of this output?:```

    2020-02-25 11:45:07 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 105 child 255
    2020-02-25 11:45:07 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:TSF:MSG:READ,105-105-0,s=255,c=3,t=12,pt=0,l=3,sg=0:1.0
    2020-02-25 11:45:07 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 105 child 255
    2020-02-25 11:45:07 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:TSF:MSG:READ,105-105-0,s=0,c=0,t=35,pt=0,l=0,sg=0:
    2020-02-25 11:45:07 WARNING (MainThread) [mysensors] Not a valid message: Not valid message sub-type: 35 for dictionary value @ data['sub_type']
    2020-02-25 11:45:07 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:TSF:MSG:READ,105-105-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
    2020-02-25 11:45:07 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:TSF:MSG:SEND,0-0-105-105,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
    2020-02-25 11:45:07 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:TSF:MSG:READ,105-105-0,s=0,c=1,t=37,pt=4,l=4,sg=0:1
    2020-02-25 11:45:07 WARNING (MainThread) [mysensors] Child 0 is unknown
    2020-02-25 11:45:07 DEBUG (SyncWorker_1) [mysensors.persistence] Saving sensors to persistence file /home/raymond/.homeassistant/mysensors1.pickle
    


  • I actually have the same problem and do not know where it is coming from.
    I tried several time to delete mysensors.json file and restart AH to try to troubleshoot it without success.

    This is the errors I get exactly:

    2020-02-25 19:07:32 ERROR (MainThread) [homeassistant.components.mysensors.device] Error updating Grow monitor 30 3
    Traceback (most recent call last):
      File "/usr/src/homeassistant/homeassistant/components/mysensors/device.py", line 108, in update
        await self._async_update_callback()
      File "/usr/src/homeassistant/homeassistant/components/mysensors/device.py", line 134, in _async_update_callback
        await self.async_update_ha_state(True)
      File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
        self._async_write_ha_state()
      File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 330, in _async_write_ha_state
        unit_of_measurement = self.unit_of_measurement
      File "/usr/src/homeassistant/homeassistant/components/mysensors/sensor.py", line 85, in unit_of_measurement
        float(self.gateway.protocol_version) >= 1.5
    ValueError: could not convert string to float: '2.3.2'
    

    I checked the file mentioned in the last line here: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/mysensors/sensor.py
    I see that V_LEVEL doesn't have a S_MOISTURE corresponding it to (line 32).
    Could the error comes from the unit of measurement is not mentioned for S_MOISTURE type of sensors?



  • @Meach
    I guess there's only one way to find out: Add the S_MOISTURE definition on line 36 in sensors.py manually, restart HA and give it a try.

        "V_LEVEL": {
            "S_SOUND": ["dB", "mdi:volume-high"],
            "S_VIBRATION": ["Hz", None],
            "S_LIGHT_LEVEL": ["lx", "mdi:white-balance-sunny"],
            "S_MOISTURE": ["%", "mdi:water-percent"],
        },
    

    Since the measurement in your sketch seems to be tensiometric, I'm not certain if % is the correct unit to choose here, but I guess in general people would assume that S_MOISTURE is a volumetric measurement representing the percentage of water per volume in the soil. So you might want to change it to [None, "mdi:gauge"] or [kPa, "mdi:gauge"].

    It's weird though that the logs from both of you complain about the MySensors version string, which of course, isn't a valid float and can't be converted with float(varString).



  • Out of curiosity, I just setup a node with the sketch that @mrhutchinsonmn posted in the first post, but uploaded dummy data instead of measuring actual values (shouldn't be a problem, I just don't have a soil moisture sensor at hand). I also tried the latest version of the SoilMoistSensor.ino sketch.

    Unfortunately, I was unable to reproduce the issue. Serial output is fine, the HA log shows no errors, the sensor value is displayed in the GUI. So I doubt that the change mentioned above will have any effect. It's most likely just used to display a default unit and icon in the GUI. If there's no matching sensor type, as is the case with S_MOISTURE, it will default to a unit-less display. At least that's my understanding.

    I used MySensors 2.3.2 and Home Assistant 0.105.5 (in Docker).



  • That particular error went away with a new HA install 0.103.6. However, I continue to get data type and child unknown errors:

    020-02-26 07:47:33 WARNING (MainThread) [mysensors] Not a valid message: Not valid message sub-type: 35 for dictionary value @ data['sub_type']
    2020-02-26 07:47:34 WARNING (MainThread) [mysensors] Child 0 is unknown
    2020-02-26 07:48:05 WARNING (MainThread) [mysensors] Child 0 is unknown
    2020-02-26 07:48:36 WARNING (MainThread) [mysensors] Child 0 is unknown
    2020-02-26 07:49:07 WARNING (MainThread) [mysensors] Child 0 is unknown
    2020-02-26 07:49:30 WARNING (MainThread) [mysensors] Not a valid message: Not valid message sub-type: 21 for dictionary value @ data['sub_type']
    2020-02-26 07:49:38 WARNING (MainThread) [mysensors] Child 0 is unknown
    2020-02-26 07:50:09 WARNING (MainThread) [mysensors] Child 0 is unknown
    

    Corresponding serial monitor info:

    5235 TSF:MSG:SEND,105-105-0-0,s=0,c=1,t=37,pt=4,l=4,sg=0,ft=0,st=OK:-2
    5244 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    5250 TSF:TDI:TSL
    5252 MCO:SLP:WUP=-1
    5253 TSF:TRI:TSB
    10	0	10	10	0	10	0	0	0	0		4
    0	0	0	0	0	-10	0	0	0	0		-1
    resistance bias =5
    sensor bias compensated value = 1
    
    5307 TSF:MSG:SEND,105-105-0-0,s=0,c=1,t=37,pt=4,l=4,sg=0,ft=0,st=OK:1
    5316 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
    5321 TSF:TDI:TSL
    


  • @mrhutchinsonmn

    How have you configured MySensors in Home Assistant? I get the "not a valid message" error when I switch back to the old 1.4 protocol, which is still the default in HA.

    So I suspect that you are using the old protcol version. Please have a look at your configuration.yaml and see if you specified the current version with version: '2.0' or even 2.3. It should look something like this:

    mysensors:
      gateways:
        - device: mqtt
          persistence_file: '/config/mysensors.json'
          topic_in_prefix: 'mysensors-out'
          topic_out_prefix: 'mysensors-in'
      optimistic: false
      persistence: true
      retain: true
      version: '2.0'
    

    @Meach's issue might be down to an old HA version then, if an update fixed this particular error.



  • I found a solution for my problem. In configuration.yaml I changed:

    version: '2.3.2'
    

    to

    version: '2.3'
    

    Now the errors don't show up anymore and my node is working 🙂



  • Yes!! That worked for me!
    Thank you!



  • Worked for me too!! Using RPi Gateway.
    Thank you


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 5
  • 2
  • 8

1
Online

11.4k
Users

11.1k
Topics

112.7k
Posts