Hi community, I’m new here and I’d like to ask for help to solve my current problem.
I’m playing with Tasmota and the MQ-2 sensor. I flashed the Wemos D1 Mini with the Tasmota firmware 13.0 and connected the MQ-2 to the Analog A0 pin and configured it with MQ template. At this point I receive the value about 3.55 ppm which is 100x lower than the value. I tried to adjust the pullt up resistor with various value where I received not quite expected values. I believe that the optimal way is to adjust the incoming value and multiply it directly in the Home Assistant.
What I did:
I was to able to calcute the value under Developer Tools/Template
{{ states(‘sensor.mq_2’) | float(0) * 100 }}
but I’m not able (cannot understand) how to put this information that is visible in the sensor value
I’m not a developer and this is more than pain for me as I’m trying to solve it few weeks but without any progress. YAML is for me a bit difficult. I found a lot of information about this topic but nothing helped.
Version of my Home Assistant is 2023.6.3, Core on RPI3 (Ubuntu 22.04.3 LTS)
I’m sorry, but I don’t understand, what you’re trying to do.
Do you want to show this sensors value in the frontend? Or do you need for other things?
Either way, if you get a sensor value from an integration (like you do), you can always setup a so called template sensor, do modifications to it, and use that one to work with.
If that’s what you’re looking for, let me know, I’ll provide an example. Nonetheless, just let us know, what you want to achieve, and we’ll go from there.
thanks for reply. At this point I can see the value of CO sensor on the level 3.43ppm but I need that it shows 343ppm. Have to multiply the value 100x. I don’t know how to do it
Here is the current value but I need that it shows 343 instead 3.43 I know that when I use this {{ states(‘sensor.mq_2’) | float(0) * 100 }} then it calculates the vale but I don’t know how to replace.
That doesn’t answer, where you want to use it. But yes, the linked topic is exactly what you’re looking for - a template sensor!
The idea behind this is as follows: sensor values are sent from an integration to HA, that is the raw data for HA to work with. If you need to change something, as in your case multiply it or any other change, you need to do this afterwards. That’s where template sensors come into play. You take the raw value of one or more sensors and combine these in one template sensor, so you can use the changed value eg. to display or whatever you like. The raw data is still untouched and can be used by the system.
This goes in your configuration.yaml or if you have split up your configuration in the corresponding file:
Thanks for reply. I’ve added exactly the same you wrote and got error:
Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 11) for dictionary value @ data[‘sensor’][0][‘state’]. Got “’{{ states(‘sensor.mq_2’) | float(0) * 100 }}’\n”. (See /var/snap/home-assistant-snap/571/configuration.yaml, line 59).
Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 10) for dictionary value @ data[‘sensor’][0][‘state’]. Got ‘{{ states(‘sensor.mq_2’) | float(0) * 100 }}\n’. (See /var/snap/home-assistant-snap/571/configuration.yaml, line 59).
I created a customize.yaml file, included it to the configuration. What is working is this:
What’s changed are the apostrophes around the sensor name… They need to be " or '.
And btw. if you have time later, please read the forum rules regarding code formatting, it really is important. Not in this case, but if there are errors with indentation it is only findable with the correct formatting.
Well, the formating was the first I checked and I all the time using the configuration check under the developer tools. Unfortunately the problem still persists and I don’t know where could be the issue.
I didn’t this is exactly the problem I have. I tried it with quotes, without, various combinations, with syntax check, config reload, HA restart, RPI restart, but I’m not able to change the value. The sensor is connected to Tasmota Wemos D1 Mini via A0 sensor. I tried to adjust the value also directly in the Tasmota by add of the rule but somehow it does not work. Maybe it helps that the information is sent via MQTT.
This is what I have, it is the whole customize.yaml file. It is not is the configuration.yaml file. From above mentioned config works the “ppm” unit which is added after the measured value, but not the calculation of the value.
By this ended my pain with the adjustment of the values using templates and I’m a bit closed to better understand how great is the Home Assistant. Thank you guys for the contribution.
It’s the custom of this community forum to assign the Solution tag to the first (or best) post that provides the answer/solution to the original question/problem. In this topic, that would be paddy0174’s post.
If everyone marked their own post with the Solution tag, regardless of the assistance they received from others, it would give the impression that everyone ultimately solves their own problem.
While that will work for this sensor as it is a template sensor, there’s also good use for a sensors.yaml for sensors that are not template sensors but sensors for other integrations.
@patrik.zuffa since you’re still new, I would suggest to look into YAML packages already now. I wish I did a lot sooner than I started to migrate config. Packages keep things a lot neater. Save yourself some future admin.