Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


peejayw

1913 posts

Uber Geek
+1 received by user: 123


#310513 26-Oct-2023 17:00
Send private message

I am trying to copy and paste part of a config.yaml file into a new file. This is the clip.

 

#TempDiff
######
  - platform: template
    sensors:
      temperature_difference:
       friendly_name: "Temperature Difference"
       unit_of_measurement: '°C'
       value_template: >
             {{ ( states('sensor.lumi_lumi_weather_temperature')|float(0) - states('sensor.lumi_lumi_weather_b083df07_temperature')|float(0) )|round(2) }}

 

 

 

When I paste it in I get these errors

 

 

#TempDiff

 

######

 

  - platform: template  bad indentation of a mapping entry

 

    sensors:

 

      temperature_difference: can not read a block mapping entry; a multiline key may not be an implicit key

 

       friendly_name: "Temperature Difference"

 

       unit_of_measurement: '°C'

 

       value_template: >

 

             {{ ( states('sensor.lumi_lumi_weather_temperature')|float(0) - states('sensor.lumi_lumi_weather_b083df07_temperature')|float(0) )|round(2) }}

 

 

 

 

What am I doing wrong here?





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


Create new topic
nzkc
1634 posts

Uber Geek
+1 received by user: 1041


  #3152445 26-Oct-2023 17:36
Send private message

Probably need to see the surrounding fragments of yaml since its complaining about indentation. Could be the previous/next fragments change the indentation you need.




marpada
487 posts

Ultimate Geek
+1 received by user: 182


  #3152446 26-Oct-2023 17:41
Send private message

Hard to say as the forum software might screw the format, but the indentation below temperature_difference might be wrong, make sure it's at least 2 spaces. Does it validate if you paste the snippet on https://codebeautify.org/yaml-parser-online. ?


peejayw

1913 posts

Uber Geek
+1 received by user: 123


  #3152447 26-Oct-2023 17:59
Send private message

This is what it looks like

 

 

 





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.




peejayw

1913 posts

Uber Geek
+1 received by user: 123


  #3152448 26-Oct-2023 18:00
Send private message

It validates in the online parser.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


marpada
487 posts

Ultimate Geek
+1 received by user: 182


  #3152455 26-Oct-2023 18:42
Send private message

Indentation is important in yaml, keep it consistent at 2 spaces


fearandloathing
537 posts

Ultimate Geek
+1 received by user: 206

ID Verified
Lifetime subscriber

  #3152456 26-Oct-2023 18:44
Send private message

You’re probably missing
sensor:
Above your
- template

 
 
 

Move to New Zealand's best fibre broadband service (affiliate link). Free setup code: R587125ERQ6VE. Note that to use Quic Broadband you must be comfortable with configuring your own router.
fearandloathing
537 posts

Ultimate Geek
+1 received by user: 206

ID Verified
Lifetime subscriber

  #3152457 26-Oct-2023 18:52
Send private message

Template sensors changed a while ago
So it might be
template:
-sensor:
-name: “sensor name”
unit_of_measurement: “•c”
Etc….

bigreddog
236 posts

Master Geek
+1 received by user: 117

Subscriber

  #3152562 27-Oct-2023 10:42
Send private message

The first line "-platform: template should have no indentation. 

 

Move the whole lot back to the left (select the text and shift tab):

 

 

 





Tauranga
Quic Fibre (use R213449EPZJ3R for free setup)


peejayw

1913 posts

Uber Geek
+1 received by user: 123


  #3152580 27-Oct-2023 11:41
Send private message

Thanks for that, think I am getting close. This is what I am getting now.

 





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


eluSiveNZ
192 posts

Master Geek
+1 received by user: 42


  #3152641 27-Oct-2023 12:17
Send private message

peejayw:

 

Thanks for that, think I am getting close. This is what I am getting now.

 

 

 

I think you are using quite old config. Also i dont believe "sensorS" is correct. should it be "sensor"

 

Regardless, you can set this up in the UI quite easily - Settings\Devices & Services\Helpers - Create Helper = Template \ Template a sensor

 

Put your details from the yaml here, State Template will be your value template - if this is all correct it will show you a preview in the same window


peejayw

1913 posts

Uber Geek
+1 received by user: 123


  #3152663 27-Oct-2023 12:50
Send private message

Thanks, that looks interesting, will give it a go.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


 
 
 

Shop now on AliExpress (affiliate link).
peejayw

1913 posts

Uber Geek
+1 received by user: 123


  #3152719 27-Oct-2023 13:05
Send private message

OK, I set up a template using the data from my old file. This used to work in my previous HA config to subtract the temperature of one sensor from another to produce the difference between the two.

 

In the template sensor I have Unit of measurement as degrees C, Device Class as Temperature and State Class as Measurement.

 

The current values for those sensors are 17.4 and 16.9 respectively so I should get a result of 0.5 but instead I get 17.4.

 

Can you spot my error?

 

Many thanks.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


peejayw

1913 posts

Uber Geek
+1 received by user: 123


  #3152730 27-Oct-2023 13:43
Send private message

Never mind, typing error on my part.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


Create new topic








Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.