The main goal is to use mqtt data set ( already as entity with json format) with input_select dropdown selection to fill up the other entities with respective data.
The Data set (the sensor.plant entity is as follow)
no: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34
plantname: Tere, Karnabahar, Marul, Maydanoz, Bezelye, Bezelye (tatlı), Kekik, Fesleğen, Lavanta, Limon Otu, Adaçayı, Çilek, Çin Lahanası, Karpuz, Salatalık, Fasulye, Bakla, Dolmalık Biber (renkli), Kereviz, Frenk Soğanı, Bal Kabağı, Ispanak, Su Kabağı, İsviçre Pazı, Kabak, Kavun, Nane, Dolmalık Biber, Biber Acı, Domates, Bürüksel Lahanası, Lahana, Patlıcan, Brokoli
plantname_en: Watercress, Cauliflower, Lettuce, Parsley, Pea, Peas (Sugar), Thyme, Basil, Lavender, Lemon Balm, Sage, Strawberries, Pak-choi, Watermelon, Cucumber, Bean (Common), Bean (Broad), Bell Peppers, Celery, Chives, Pumpkin, Spinach, Squash, Swiss Chard, Zucchini, Melon, Mint, Peppers (Bell), Peppers (Hot), Tomato, Brussell Sprouts, Cabbage, Eggplant, Broccoli
plant_ec_low: 0.4, 0.5, 0.8, 0.8, 0.8, 0.8, 0.8, 1, 1, 1, 1, 1, 1.5, 1.5, 1.7, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 2, 2, 2, 2, 2, 2.5, 2.5, 2.5, 2.8
plant_ec_high: 1.8, 2, 1.2, 1.8, 1.8, 1.9, 1.6, 1.6, 1.4, 1.6, 1.6, 1.4, 2, 2.4, 2.5, 2.4, 2.4, 2.8, 2.4, 2.4, 2.4, 2.3, 2.4, 2.3, 2.4, 2.5, 2.4, 2.5, 3.5, 5, 3, 3, 3.5, 3.5
plant_ph_low: 6.5, 6, 5.5, 6, 6, 6, 5.5, 5.5, 6.4, 5.5, 5.5, 6, 5.5, 5.08, 5.8, 6, 6, 6, 6.3, 6, 5.5, 5, 5.5, 5.5, 6, 5.5, 5.5, 6, 5.5, 6.5, 6.5, 6.5, 5.5, 6
plant_ph_high: 6.8, 7, 6.5, 7, 6.8, 6.5, 6.5, 6.5, 6.8, 6.5, 6.6, 6.5, 6, 5.08, 6, 6, 6.5, 6.7, 6.7, 6.5, 6.5, 6.5, 6.5, 7, 6, 6, 6, 6.5, 7.5, 6.8, 7.5, 7, 6.5, 6.5
plant_tds_low: 280, 1050, 560, 560, 580, 580, 560, 700, 700, 700, 700, 500, 1050, 1050, 1190, 1400, 1400, 1400, 1260, 1260, 1260, 1260, 1260, 1260, 1260, 1400, 1400, 1400, 1400, 1400, 1750, 1750, 1750, 1960
plant_tds_high: 1260, 1400, 840, 1260, 1260, 1261, 1120, 1120, 980, 1120, 1120, 700, 1400, 1680, 1750, 2800, 1800, 2000, 1680, 1680, 1680, 1610, 1680, 1610, 1680, 1750, 1680, 1750, 2450, 3500, 2100, 2100, 2450, 2450
plant_temp_low: , , 20, , , , , 18, , , , 20, , , 18, , , , , , , 18, , , , , 18, 20, 20, 18, , , ,
plant_temp_high: , , 23, , , , , 25, , , , 23, , , 22, , , , , , , 24, , , , , 24, 23, 23, 25, , , ,
plant_harvest_target: , , 30, , , , , 30, , , , 60, , , 70, , , , , , , 45, , , , , 30, 90, 90, 70, , , ,
plant_daylight_target: , , 16, , , , , 16, , , , 16, , , 14, , , , , , , 14, , , , , 10, 16, 16, 16, , , ,
friendly_name: Plant
The input_select.plantname works perfect and getting option value from above data set:
The mission I need to achieve is to fill up other input data as soon as input_select.plantname has changed.
Accordingly I have created an automationas follow:
- id: '1615792052600'
alias: Set input_number.plant_ec_low
description: ''
trigger:
- platform: state
entity_id: input_select.plantname
condition: []
action:
- service: input_number.set_value
entity_id: input_number.plant_ec_low
data_template:
value: "(states.sensor.plant.attributes.plant_ec_low[state_attr(trigger.entity_id,'options').index(states(trigger.entity_id))]) | float"
- service: input_number.set_value
entity_id: input_number.plant_ec_high
data_template:
value: "(states.sensor.plant.attributes.plant_ec_high[state_attr(trigger.entity_id,'options').index(states(trigger.entity_id))]) | float"
mode: single
The values are works good in Developper Tools > Template as normal in following structure:
{{ states.sensor.plant.attributes.plant_ec_low[state_attr('input_select.plantname','options').index(states('input_select.plantname'))]}}
{{ states.sensor.plant.attributes.plant_ec_high[state_attr('input_select.plantname','options').index(states('input_select.plantname'))]}}
But, after all try I couldn’t get successful to get the value from automation. Automation does not give any error as above, the only difference with template complier request me to convert dictionary values to the float. That’s why I’ve added | float to the end. However if I add the | float in developer tools > template; values printing as 0,00
I will be grateful for any advise to solve template in automation