Lambda Syntax Help for EC Sensor

I can’t figure out how to get the syntax correct for this lambda call. I am trying to use a DFROBOT EC sesnosr in esp home.

DFROBOT sensor
https://wiki.dfrobot.com/Analog_EC_Meter_SKU_DFR0300

my current yaml

# Temperature Compensated Voltage
  - platform: template
    name: "OG EC TCV"
    id: temp01_comp_v
    unit_of_measurement: 'v'
    accuracy_decimals: 3
    lambda: 'return ((id(ogec_raw).state) / (1 + (0.0185 * ((id(probe01).state) - 25.0))));'
    update_interval: 10s
    internal: true

# Temperature Compensated EC
  - platform: template
    name: "OG EC"
    id: ogec01
    icon: "hass:water-opacity"
    unit_of_measurement: 'PPM'
    accuracy_decimals: 0   
    lambda:
      if (temp01_comp_v<=448) {ogec01 =6.84*temp01_comp_v-64.32;   #1ms/cm<EC<=3ms/cm
      } else if(temp01_comp_v<=1457) {ogec01=6.98*temp01_comp_v-127;  #3ms/cm<EC<=10ms/cm
      }else ogec01=5.3*temp01_comp_v+2278;                           #10ms/cm<EC<20ms/cm
      ogec01/=1000; 

Anyone able to help?

What error message do you get?

while parsing a block mapping
  in "/config/esphome/garden-og-dosing.yaml", line 78, column 5:
      - platform: template
        ^
expected <block end>, but found '}'
  in "/config/esphome/garden-og-dosing.yaml", line 86, column 7:
          } else if(temp01_comp_v<=1457) { ... 
          ^
   lambda: |-
      if ((id(temp01_comp_v).state)<=448) { return (6.84*(id(temp01_comp_v).state)-64.32);
        }else if ((id(temp01_comp_v).state)<=1457) { return (6.98*(id(temp01_comp_v).state)-127);
        }else return (5.3*(id(temp01_comp_v).state)+2278);

This seemed to fix it just turned it into a retrun statement and some brackets.

1 Like