Create your OWN Template Sensor with Home Assistant Coding Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ก.ค. 2024
  • ★FREE Home Assistant Course★: courses.leonardosmarthomemake...
    Use Home Assistant Templating with an If Statement to create a new sensor based on information about energy monitoring.
    ★My Gear★
    kit.co/smarthomemakers/gettin...
    kit.co/smarthomemakers/how-to...
    kit.co/smarthomemakers/conten...
    ★★Connect with me ★★
    ☕Coffee☕ www.buymeacoffee.com/natureboss
    🌐Web🌐 leonardosmarthomemakers.com/b...
    📘Facebook📘 / leonardosmarthomemakers
    🐦Twitter🐦 / smarthomemaker2
    #smarthomemakers #homeassistant #smartthome
    ★★ Contents ★★
    00:00 - Before Coding
    01:34 - Templating #1
    06:43 - If, Else If
    08:55 - TOP TIP
    10:00 - Sensor in Configuration
    12:18 - Demo
    DISCLAIMER: This TH-cam video description contain affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This allows us to continue to make videos like this.
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 139

  • @tympeters7071
    @tympeters7071 2 ปีที่แล้ว +2

    Thank you so much. Just two weeks into Home Assistant and struggling with 'custom sensors.' This was the perfect introduction!

  • @MrRowbeartoes
    @MrRowbeartoes 2 ปีที่แล้ว +2

    Sir, you have opened my mind to new ideas! I've seen the dryer power monitor before and it's on my list of to-dos, but you have me thinking about it differently. Thank you! I feel better prepared to get started.

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Robert, my pleasure! Have a happy new year !

  • @Damien_D
    @Damien_D 11 หลายเดือนก่อน

    Excellent Tutorial. I'm an experienced coder but a noob to Home Assistant so I needed some help to get over the first hurdles in a new interface and language. This was exactly what I needed. I'll be watching your whole series when I have time. Thanks.

    • @SmartHomeMakers
      @SmartHomeMakers  10 หลายเดือนก่อน

      Thanks Damien! In which languages do you code in?

  • @procast
    @procast 9 หลายเดือนก่อน

    Thank you so much for making this tutorial. So far the most straight forward and clean way of doing it.

  • @javandermerwe
    @javandermerwe 2 ปีที่แล้ว

    Once again, thanks for a very helpful video. Your content selection and quality is constantly growing and I enjoy your channel 👍

  • @RobinDeBecker
    @RobinDeBecker 2 ปีที่แล้ว

    This video will help me a lot with templating. Always had struggles with it, but now it is more clear for me. Many thanks 🙂

  • @thad3229
    @thad3229 2 ปีที่แล้ว

    Thank you for making this video. I'm a programmer by day, but a lot of the explanations around custom sensors seemed as clear as mud until I found your video. This breaks it down and explains it very clearly. You have saved me a lot of future headache, thank you so much for the simple and concise explanation!

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว +1

      Thanks Thad ! Appreciate you watching the video :)

    • @thad3229
      @thad3229 2 ปีที่แล้ว

      @@SmartHomeMakers thanks for making them

  • @ArranAsh
    @ArranAsh 10 หลายเดือนก่อน

    Thank you so much! Great for presenting custom ESPHome devices better!

  • @stuartclark4045
    @stuartclark4045 3 หลายเดือนก่อน

    Brilliant, so simple to follow. Thank you!

  •  2 ปีที่แล้ว

    wooooww just what I was searching. thank you very much!!!

  • @waynenocton
    @waynenocton 2 ปีที่แล้ว

    Excellent! I had no idea what templating was! I actually had made one months ago I think, made a switch and a contact sensor into a cover(garage door). But you explanation of those crazy brackets was super helpful, last time I did any programming was in the early 80’s and it was the Basic language, so I’m pretty much less than zero on programming knowledge. Thanks a bunch!

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว +1

      The basics of coding might not have changed much :) are you learning any new language now ?

    • @waynenocton
      @waynenocton 2 ปีที่แล้ว

      @@SmartHomeMakers no I’m not, except the Home Assistant and Tasmota stuff.

  • @user-oe5yo4dv9c
    @user-oe5yo4dv9c 7 หลายเดือนก่อน

    Excellent video. Clear and precise presentation!

  • @mindracing
    @mindracing 2 ปีที่แล้ว

    Well done. That's clarified a whole bunch of things. Thank you.

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Thanks Ash! Which video would you like to see next?

    • @mindracing
      @mindracing 2 ปีที่แล้ว

      @@SmartHomeMakers More on templating would be good

  • @Mrdsmith500
    @Mrdsmith500 ปีที่แล้ว

    This is what I was looking for. Thank you so much.

  • @coobek2k
    @coobek2k 2 ปีที่แล้ว +3

    Thanks for the tutorial, really nicely explained.
    I wish there was entities ID autocomplete in this editor, just like in VS Code.
    Would make playing around it so much easier.

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว +2

      Kuba, you are right it would be a nice addition!

  • @OPB682
    @OPB682 2 ปีที่แล้ว +1

    +1 for the tutorial. I have no experience with ginja so this is great

  • @GioBen68
    @GioBen68 2 ปีที่แล้ว

    Very well explained and very useful tip 👍🏼👍🏼thanks

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Thanks GioBen! Much appreciated your comment !

  • @WoottonRivers
    @WoottonRivers 2 ปีที่แล้ว

    Great video. Thank you

  • @robertaccess
    @robertaccess 2 ปีที่แล้ว

    This is a very useful video... great job

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Thanks Robert appreciate the constant support !

  • @bgable7707
    @bgable7707 11 หลายเดือนก่อน

    Enjoying your video's! Very helpful! HOWEVER, I missed the part where the "sensor.tumble_dryer_power" entity came from. Did you define it as part of the Shelly1PM? I'm currently only using esp's.

  • @etiennedeklerk
    @etiennedeklerk 2 ปีที่แล้ว

    Nice bite size & useful intro to templates.

  • @TheCowboysdude
    @TheCowboysdude 2 ปีที่แล้ว +1

    1000 times Thank you!! Being new to this is overwhelming but you helped greatly!! I made a simple little sensor to show whether I'm home or not... it's a start to bigger and better things :)

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Hi John! Please share your code with us :)

    • @TheCowboysdude
      @TheCowboysdude 2 ปีที่แล้ว

      @@SmartHomeMakers Not sure how to or if I even can format code here but here it is.... VERY simple LOL I made that sensor that's called john_presence and put it in my sensor dir [which is included in my config.yaml]
      - platform: template
      sensors:
      john_presence:
      friendly_name: John presence
      value_template: >-
      {% if is_state('device_tracker.sm_f926u1', 'not_home') %}
      John's Out {% else %}
      John's In {% endif %}

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว +2

      @@TheCowboysdude you can also achieve this without templating by linking your device tracker to a person in HA! Regardless good work!

    • @TheCowboysdude
      @TheCowboysdude 2 ปีที่แล้ว +1

      @@SmartHomeMakers did not know that!!! Thank you!! I will try that too. What I was really trying to do was show a picture and have it change when I wasn't home.....but that's been a bit over my head :)

  • @JoseBerruezo
    @JoseBerruezo 2 ปีที่แล้ว

    Very nice explanation.

  • @kodeypatterson8973
    @kodeypatterson8973 2 ปีที่แล้ว

    Great video

  • @ronm6585
    @ronm6585 2 ปีที่แล้ว

    Nice! Thanks.

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Thanks Ron, I hope you have a great 2022

    • @ronm6585
      @ronm6585 2 ปีที่แล้ว

      @@SmartHomeMakers Thank you and Happy New Year!

  • @altussss
    @altussss 2 ปีที่แล้ว

    plenty of examples presented in a simple way 😁👍

  • @louisviciedo
    @louisviciedo ปีที่แล้ว

    Thanks Gio, a great video on templates! Much needed as I expand my use cases in HAS. By chance do you have a video that returns a specific entity that triggered an automation? For example I have 5 smoke sensors and I want my notification to return the specific sensor that triggered the automation. Thank you!

    • @SmartHomeMakers
      @SmartHomeMakers  ปีที่แล้ว

      Thanks Louis, let me know what you think about my other templating videos

  • @singaporepastor
    @singaporepastor 2 ปีที่แล้ว

    thanks for the tutorial! i'm getting this error, any idea what is going wrong here?
    'float' got invalid input 'unknown' when rendering template '{% if states("sensor.dryer_power")|float == 0 %} Off {% elif states("sensor.dryer_power")|float

  • @xXDeadJesterXx
    @xXDeadJesterXx ปีที่แล้ว

    Setting up an automation for our dryer is the one thing I've been unable to do so far. I live in the U.S. and we have the funky plugs for our dryers, so using a normal power monitor smart plug won't work. I've heard of Shelly before, do you have a link to the one you used? I know Shelly offers some products here in the US, so hopefully I can get one that will work.

  • @celinevermolen1618
    @celinevermolen1618 2 ปีที่แล้ว

    Very clear and much obliged. Only struggle here is to make the outcome of the if/else a trigger for an automation. I.e. if status dryer changes from standby to drying: send me a message or whatever action needed.

    • @SmartHomeMakers
      @SmartHomeMakers  ปีที่แล้ว

      Hi Celine, you can use the from to in a trigger to look at the status!

  • @vegaswayne247
    @vegaswayne247 2 ปีที่แล้ว +1

    Thanks for the video. I got it to work with a Sonoff S31PM by using {% if state_attr('switch.sonoff_s31pm', 'power') == 0 %} in place of what you were using.

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Is that because the sonoff switch has power as an attribute of the device and not its own entity

    • @vegaswayne247
      @vegaswayne247 2 ปีที่แล้ว

      @@SmartHomeMakers Yes, it is an attribute not its own entity. I'm using the HACS integration to get it to work in Home Assistant.

  • @lcarter194
    @lcarter194 ปีที่แล้ว

    Thanks for all the work and time you have given us. I was not able to use the term state. When I went looking on other sites I found a different way of creating sensor as follows
    - platform: template
    sensors:
    quickpot:
    friendly_name: 'fastcook'
    value_template: >
    {% if states("sensor.dishwasher_energy_current") | float == 0 %}
    OFF
    {% elif states("sensor.dishwasher_energy_current") | float

  • @Shaq2k
    @Shaq2k 2 ปีที่แล้ว

    Love your coding videos. Keep up the good work. Could you maybe do a sensor for daily power consumption?

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Hi Oystein! Yes you could, want would you use it for? Like an automation to turn off the device once it reached a certain power level? Not sure how practical on a family basis that could be :)

    • @Shaq2k
      @Shaq2k 2 ปีที่แล้ว

      @@SmartHomeMakers Nice. I simply want to see daily consumption of my smart plugs etc. As they are out of the box, they only show current consumption and total consumption as far as I can tell. Even in the energy dashboard. Sure, the individually monitored nodes show the daily consumption, but not when I click on one of them; then they show just the total consumption. Which in reality tells nothing at all

  • @mosth8ed
    @mosth8ed 2 ปีที่แล้ว

    Are you kidding? My wife would love a tumble dryer as a present. Definitely do that.

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Why not:)

    • @TheUnofficialMaker
      @TheUnofficialMaker 2 ปีที่แล้ว

      You must be the guy that bought yourself a new iPhone, gave your son an iPad, your daughter an iPod and your wife an iRon! lol

  • @rickz6006
    @rickz6006 2 ปีที่แล้ว

    Thank you for this, I have searched for any syntax documentation for creating templates and have had to rely on looking at other users code for clues, can you point at such documentation? For example I first thought to use a case statement rather than if but can’t find if one is available for use!
    I also found that I could just update templates rather than restarting HA, saved a ton of time with my many errors and restarts.
    Thanks for what you are doing to help us all!

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Hi Rick! There is a jinja2 templating documentation from the developer tool haven’t got a link on me :)

    • @rickz6006
      @rickz6006 2 ปีที่แล้ว

      @@SmartHomeMakers Maybe my biggest issue is that I never know if I am coding Yaml, Python or Jinja. None of which I have used before. Thanks!

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      @@rickz6006 python is the programming language that HA is built upon, yaml mainly is seen as a configuration language as is jinja

    • @simonburke6681
      @simonburke6681 2 ปีที่แล้ว

      I find the same, it's hard to figure out the prefix etc. It would be nice if there was a homeassistant examples cheat sheet trying to relate to the jinja documents is hard

  • @akram1402
    @akram1402 2 ปีที่แล้ว

    Thanks for the information.. I like the sound of the keyboard.. Can you tell me what kind it is?

  • @ARGONAUTA34
    @ARGONAUTA34 ปีที่แล้ว

    Hello and congratulations for the home assistant videos, I need help on the dryer status template. How can I insert a delay that if it is under 6 w for 10 seconds is it stanbay?

    • @SmartHomeMakers
      @SmartHomeMakers  ปีที่แล้ว

      Would that be a condition in an automation?

    • @ARGONAUTA34
      @ARGONAUTA34 ปีที่แล้ว

      @@SmartHomeMakers Hello,no in this sensor, put a 10 second delay before the dryer gives me standby
      - sensor:
      - name: stati asciugatrice
      state: >
      {% if states("sensor.tz3000_gjnozsaz_ts011f_active_power")|float == 0 %}
      off
      {% elif states("sensor.tz3000_gjnozsaz_ts011f_active_power")|float

  • @user-mfsc-2024
    @user-mfsc-2024 ปีที่แล้ว

    the sensor name will convert to xxxx_xxxx from name in template automatically right ?

  • @n.r.2258
    @n.r.2258 2 ปีที่แล้ว

    You have just solved me another problem …. just one question left: how do you describe a value between two values let’s say „if sensor value is>= 40 but

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Hi NR I forgot if I answered this question already ?

  • @n.r.2258
    @n.r.2258 2 ปีที่แล้ว

    Danke!

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Welcome!

    • @n.r.2258
      @n.r.2258 2 ปีที่แล้ว

      @@SmartHomeMakers
      But I have one question left … what is the command if you want a range for the sensor …. ie between 40 and 50 …
      In you’re sample, you just covered 1 value i.e. one value …. how about between 2 values ?

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      @@n.r.2258 have you tried >= 40 and

    • @n.r.2258
      @n.r.2258 2 ปีที่แล้ว

      @@SmartHomeMakers
      {% if states ('sensor.wasser_sensor') | float >= 40 and

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      you need to repeat the states portion again states ('sensor.wasser_sensor') | float

  • @kokzos
    @kokzos 2 ปีที่แล้ว

    it will work with sonoff ewelink?

  • @shawnrichards7935
    @shawnrichards7935 2 ปีที่แล้ว

    Can home assistant be used to send IR or RS232 command to control tv, audio receivers etc…?

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      With something like a broad link you can!

    • @TheUnofficialMaker
      @TheUnofficialMaker 2 ปีที่แล้ว +1

      @@SmartHomeMakers can you make a video on it!

  • @alexcapone3284
    @alexcapone3284 2 ปีที่แล้ว

    I am trying to evaluate the last notification on my phone whether it contains a list of words and if NOT contain any of the specified words then it should update the sensor. What is the best way to write this code?

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Hi Alex, nice use case, not sure home assistant is your answer for this!

  • @Rich33527
    @Rich33527 2 ปีที่แล้ว

    Can you assign a unique id to the template sensor?

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      What are you trying to achieve Damuson?

    • @Rich33527
      @Rich33527 2 ปีที่แล้ว

      @@SmartHomeMakers Thanks for the reply. I honestly cant remember the exact circumstances on what I was trying to do. This was when I was first learning Home Assistant. I was trying to do something but was getting an error since there was no unique ID. I obviously found a workaround and most likely a better way than I was thinking. I just cant remember what...

  • @Paata02
    @Paata02 ปีที่แล้ว

    How do we know when drying finishes to get notifications?

    • @SmartHomeMakers
      @SmartHomeMakers  ปีที่แล้ว

      When the power consumption drops to nearly 0 for a certain amount of time, depending on your model!

  • @highland-oldgit
    @highland-oldgit ปีที่แล้ว

    11:41 Line 391 'Template' disappears ? I followed the instructions and no errors but my sensor does not appear afterward.

  • @cchris3
    @cchris3 2 ปีที่แล้ว

    Thanks for the video. I followed everything you did but after restarting I do not get a new sensor.tumble_dryer. Any idea why?

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Hi Chris, did you get any error messages? Do you want to share your YAML?

    • @cchris3
      @cchris3 2 ปีที่แล้ว

      @@SmartHomeMakers Got this error;
      The following integrations and platforms could not be set up:
      template
      Please check your config and logs.
      Logger: homeassistant.config
      Source: config.py:464
      First occurred: 1:27:53 PM (1 occurrences)
      Last logged: 1:27:53 PM
      Invalid config for [template]: expected dictionary for dictionary value @ data['sensors']. Got [OrderedDict([('name', 'Washing Machine'), ('state', '{% if states("sensor.washer_power")|float

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      @@cchris3 can’t spot anything wrong! Is template aligned to the left no spaces ?

    • @cchris3
      @cchris3 2 ปีที่แล้ว

      @@SmartHomeMakers Yea, left aligned with no spaces. "Check Config" says valid and restart happens without issues. But just dont see the new sensor. Thanks.

  • @CalMUK91
    @CalMUK91 6 หลายเดือนก่อน

    I get a strange error on startup saying -sensor is an invalid option for -template

  • @russgulley7193
    @russgulley7193 ปีที่แล้ว

    Thanks for the great video!
    I'm using Developer Tools, Template
    But, I'm stuck here is my code:
    ```
    (% if states("number.humidifier_target_level") == 55 %)
    off
    (% else %)
    on
    (% endif %)
    ```
    I am getting this error:
    This template does not listen for any events and will not update automatically.
    I have checked the States and it shows 55.
    Any help would be greatly appreciated!
    TIA

    • @SmartHomeMakers
      @SmartHomeMakers  ปีที่แล้ว

      Can you try to use states("number.humidifier_target_level") ? What do you get?

    • @russgulley7193
      @russgulley7193 ปีที่แล้ว

      @@SmartHomeMakers Thanks, that is the same as I'm using. Same error.

  • @Chesterflaps
    @Chesterflaps ปีที่แล้ว

    You create the code in templates but then you don't use that when you're typing the code into the config yaml so I am confused. I have got my code in the template but what do i do with that? I cannot see why you do that first as you just create some different code in the config yaml

  • @ryantrainor2
    @ryantrainor2 2 ปีที่แล้ว

    Can this be used to make a virtual motion or contact sensor in HA?

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Hi Ryan, what is your use case for a virtual motion sensor?

    • @ryantrainor2
      @ryantrainor2 2 ปีที่แล้ว

      Hi, Thanks for replying. I’m trying to find away to trigger an Alexa routine with ahome assistant automation.

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว +1

      @@ryantrainor2 I think you will find this article a great read: robpickering.com/integrate-iotty-wall-switches-with-home-assistant/

    • @ryantrainor2
      @ryantrainor2 2 ปีที่แล้ว

      Thank you I’ll check it out much appreciated!

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว +1

      @@ryantrainor2 Have a great day/evening!

  • @rudyhenderson5002
    @rudyhenderson5002 ปีที่แล้ว

    Studio Code editor throws immediate error
    template:
    - sensor: incorrect type expected array
    state:
    Any ideas? thx

  • @Boabee
    @Boabee 2 ปีที่แล้ว

    I followed this video to a T. My template works within the generator but every line of code throws back an error. As soon as i write the word template: i cant seem to correct it at all.

  • @thepyropc_
    @thepyropc_ 2 ปีที่แล้ว

    HEy whenever i do the check i get a config invalid for
    Integration error: name - Integration 'name' not found.
    Integration error: platform - Integration 'platform' not found.
    Integration error: host - Integration 'host' not found.
    i have no errors on my code and it is exactly the same as yours other than the name ( i am running mine for the washer right now)

    • @thepyropc_
      @thepyropc_ 2 ปีที่แล้ว

      and if i remove what i just added it says the config is fine so its something in this it doesn't like. I'm out of ideas of what could be wrong lol

    • @thepyropc_
      @thepyropc_ 2 ปีที่แล้ว

      figured it out by adding it it made another part in my yaml freak out

    • @SmartHomeMakers
      @SmartHomeMakers  2 ปีที่แล้ว

      Hi Patrick! I’m glad you figured it out how did you do it ?

    • @thepyropc_
      @thepyropc_ 2 ปีที่แล้ว

      @@SmartHomeMakers Sadly had to rebuild my whole home assistant install (backups wouldn't restore for some reason_ so just had to do it all again.......
      but this time went way faster lol

    • @thepyropc_
      @thepyropc_ 2 ปีที่แล้ว

      @@SmartHomeMakers
      #washer#
      template:
      - sensor:
      - name: Washer Status
      state: >
      {% if states("sensor.washer_energy_power")| float == 0 %}
      Idle
      {% elif states("sensor.washer_energy_power")| float
      {% if states("sensor.dryer_energy_power")| float == 0 %}
      Idle
      {% elif states("sensor.dryer_energy_power")| float

  • @brentwesley6206
    @brentwesley6206 2 ปีที่แล้ว

    Thanks for the video. BTW you have a spelling mistake in your splash screen. Cobing instead of Coding :D

  • @WOTBLITZ_-xx1uf
    @WOTBLITZ_-xx1uf 9 หลายเดือนก่อน

    Man, i use HA since 2018 and some of my automation using template by copy cat, i just understand the logic of the code with this tutorial. How poor my knowledge. Thanks so much

  • @andrejo2459
    @andrejo2459 ปีที่แล้ว

    Imej itu terlalu menyinggung perasaan