How to convert kb/s to mbps in a sensor template?

The official Tautulli component gets the bandwidth but in kb/s… I created a template sensor for it but I would like to convert the data to mbps… Possible?


my sensors:

##official Tautulli
  - platform: tautulli
    host: 192.168.1.5
    port: 32500
    api_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx''
    monitored_conditions:
      - title
      - platform
      - player
      - ip_address
      
# Tautulli sensors
  - platform: template
    sensors:
      tautulli_count_total:
        friendly_name: 'Total streams'
        value_template: '{{ states.sensor.tautulli.attributes["stream_count_transcode"] }}'    
      tautulli_count_transcode:
        friendly_name: 'Transcoded streams'
        value_template: '{{ states.sensor.tautulli.attributes["stream_count_transcode"] }}'
      tautulli_direct_plays:
        friendly_name: 'Direct Plays'
        value_template: '{{ states.sensor.tautulli.attributes["stream_count_direct_play"] }}'
      tautulli_direct_streams:
        friendly_name: 'Direct Streams'
        value_template: '{{ states.sensor.tautulli.attributes["stream_count_direct_stream"] }}'  
      tautulli_wan_bandwidth:
        friendly_name: 'WAN bandwidth'
        value_template: '{{ states.sensor.tautulli.attributes["wan_bandwidth"] }}'
        unit_of_measurement: "Mbps"
      tautulli_lan_bandwidth:
        friendly_name: 'LAN bandwidth'
        value_template: '{{ states.sensor.tautulli.attributes["lan_bandwidth"] }}'
        unit_of_measurement: "Mbps"
      tautulli_total_bandwidth:
        friendly_name: 'Total bandwidth'
        value_template: '{{ states.sensor.tautulli.attributes["total_bandwidth"] }}'
        unit_of_measurement: "Mbps"

if the units are kbs, just divide the result by 1000

      tautulli_total_bandwidth:
        friendly_name: 'Total bandwidth'
        value_template: "{{ state_attr('sensor.tautulli','total_bandwidth') / 1000 }}"
        unit_of_measurement: "Mbps"
1 Like

Thanks, that works.
I found another way (which is basically the same) but needed to add the round option as well…
I thought we couldn’t devide…

# Tautulli sensors
  - platform: template
    sensors:
      tautulli_count_total:
        friendly_name: 'Total streams'
        value_template: '{{ states.sensor.tautulli.attributes["stream_count_transcode"] }}'    
      tautulli_count_transcode:
        friendly_name: 'Transcoded streams'
        value_template: '{{ states.sensor.tautulli.attributes["stream_count_transcode"] }}'
      tautulli_direct_plays:
        friendly_name: 'Direct Plays'
        value_template: '{{ states.sensor.tautulli.attributes["stream_count_direct_play"] }}'
      tautulli_direct_streams:
        friendly_name: 'Direct Streams'
        value_template: '{{ states.sensor.tautulli.attributes["stream_count_direct_stream"] }}'  
      tautulli_wan_bandwidth:
        friendly_name: 'WAN bandwidth'
        value_template: '{{ states.sensor.tautulli.attributes["wan_bandwidth"] | multiply(0.001) | round(2) }}'
        unit_of_measurement: "Mbps"
      tautulli_lan_bandwidth:
        friendly_name: 'LAN bandwidth'
        value_template: '{{ states.sensor.tautulli.attributes["lan_bandwidth"] | multiply(0.001) | round(2) }}'
        unit_of_measurement: "Mbps"
      tautulli_total_bandwidth:
        friendly_name: 'Total bandwidth'
        value_template: '{{ states.sensor.tautulli.attributes["total_bandwidth"] | multiply(0.001) | round(2) }}'
        unit_of_measurement: "Mbps"
3 Likes

you can divide, just not by zero :wink:

Do you mind sharing those lovelace cards on the plex stats? They look awesome.

Sure, I use the Plex, Tautulli sensors and custom “text-element” along with the image

  - type: picture-elements 
    image: /local/pics/plex/plexbanner.jpg   
    elements:        
      - type: custom:text-element
        text: "<b style='color: orange; font-size: 16px'>Total </b>"
        style: {left: 20%, top: 14%}        
      - type: state-label
        entity: sensor.plex_sf_network
        style: {color: white, font-size: 16px, left: 20%, top: 26%}
        
      - type: custom:text-element
        text: "<b style='color: orange; font-size: 16px'>Direct play </b>"
        style: {left: 55%, top: 14%}                  
      - type: state-label
        # prefix: 'Direct play: '
        entity: sensor.tautulli_direct_plays
        style: {color: white, font-size: 16px, left: 55%, top: 26%}    

      - type: custom:text-element
        text: "<b style='color: orange; font-size: 16px'>Direct stream </b>"
        style: {left: 20%, top: 44%}               
      - type: state-label
        entity: sensor.tautulli_direct_streams
        style: {color: white, font-size: 16px, left: 20%, top: 56%}    

      - type: custom:text-element
        text: "<b style='color: orange; font-size: 16px'>Transcode </b>"
        style: {text-align: left,left: 55%, top: 44%}             
      - type: state-label
        entity: sensor.tautulli_count_transcode
        style: {color: white, font-size: 16px, left: 55%, top: 56%}    

      - type: custom:text-element
        text: "<b style='color: orange; font-size: 16px'>LAN bandwidth </b>"
        style: {left: 20%, top: 74%}               
      - type: state-label
        entity: sensor.tautulli_lan_bandwidth
        style: {color: white, font-size: 16px, left: 20%, top: 86%}      

      - type: custom:text-element
        text: "<b text-align: left, style='color: orange; font-size: 16px'>WAN bandwidth </b>"
        style: {left: 55%, top: 74%}             
      - type: state-label
        entity: sensor.tautulli_wan_bandwidth
        style: {color: white, font-size: 16px, left: 55%, top: 86%}
2 Likes

Thanks dude! Got it all setup and it looks great!

1 Like

Ok this is wow and everyting just one issue for me I cant get the custom:text-element to work.
I’m using hassio and switched to ui-lovelace.yaml instead of the storage option. I downloaded the text-element.js and linked it in resources under my ui-lovelace.yaml but alas I keep getting red waring that custom:text-element does not exist :frowning:. anybody able to help. Yes i’ma noob and fairly new but not stuped. so please be patient with me. thx all in advance

my ui-lovelace.yaml

# Home Title
title: HomeServer
# Include external resources here.
resources:
  - url: /local/text-element.js?v=0
    type: js
views:
#Tabs
# Overview of entire house
#---------------------------------------------------------
  - title: Overview
    cards:
    - type: picture-elements 
      image: /local/plexbanner.jpeg   
      elements:        
        - type: custom:text-element
          text: "<b style='color: orange; font-size: 16px'>Total </b>"
        - type: state-label
          entity: sensor.plex
          style: {color: white, font-size: 16px, left: 20%, top: 26%}

ok fault on my end I fixe it.

One more question how did you make those graph cards

how did you fixed it? i got the same error…

post what you’re putting in the card field. Most likely your configuration is wrong.

cards:
      - type: picture-elements 
        image: /local/plexbanner.jpeg   
        elements:        
        - type: custom:text-element
          text: "<b style='color: orange; font-size: 16px'>Total </b>"
          style: {left: 20%, top: 14%}        
        - type: state-label
          entity: sensor.plex
          style: {color: white, font-size: 16px, left: 20%, top: 26%}
        
        - type: custom:text-element
          text: "<b style='color: orange; font-size: 16px'>Direct play </b>"
          style: {left: 55%, top: 14%}                  
        - type: state-label
          entity: sensor.tautulli_direct_plays
          style: {color: white, font-size: 16px, left: 55%, top: 26%}     
        
        - type: custom:text-element
          text: "<b style='color: orange; font-size: 16px'>Direct stream </b>"
          style: {left: 20%, top: 44%}               
        - type: state-label
          entity: sensor.tautulli_direct_streams
          style: {color: white, font-size: 16px, left: 20%, top: 56%}     
        
        - type: custom:text-element
          text: "<b style='color: orange; font-size: 16px'>Transcode </b>"
          style: {text-align: left,left: 55%, top: 44%}             
        - type: state-label
          entity: sensor.tautulli_count_transcode
          style: {color: white, font-size: 16px, left: 55%, top: 56%}     
        
        - type: custom:text-element
          text: "<b style='color: orange; font-size: 16px'>LAN bandwidth </b>"
          style: {left: 20%, top: 74%}               
        - type: state-label
          entity: sensor.tautulli_lan_bandwidth
          style: {color: white, font-size: 16px, left: 20%, top: 86%}       
        
        - type: custom:text-element
          text: "<b text-align: left, style='color: orange; font-size: 16px'>WAN bandwidth </b>"
          style: {left: 55%, top: 74%}             
        - type: state-label
          entity: sensor.tautulli_wan_bandwidth
          style: {color: white, font-size: 16px, left: 55%, top: 86%}

and did you install text-element and link the resources correctly?

haha, i’m noob… i did not installed the custom text-element.

Well that’s your problem. I recommend installing HACS to manage your custom items. It makes easy to install then you just copy the resource from the bottom of each page.

1 Like

so i tried this, it loads for a second, but then i get an error saying custom element doesn’t exist: text-element

i can load the resource just fine in my browser

resources:
  - url: /local/custom-lovelace/upcoming-media-card/upcoming-media-card.js
    type: js
  - url: /local/layout-card.js
    type: module
  - url: /local/text-element.js
    type: js


views:
  - tq

seems to have worked after a fancy reboot! Thanks for the card

I just upgraded Home Assistant 2022.7.5. Unfortunately, everything related to this stopped working.

UPDATE: I was able to get everything working again, except for the archived custom:text-element HACS addon (mentioned several times in my lovelace card code below). I’m not even sure what exactly it does. I still have it’s source files saved under:

\config\www\community\text-element

Do I remove the archived custom:text-element HACS addon completely? What do I put in its place and what do I put instead in my card code below.

Templates:

      tautulli_wan_bandwidth:
        friendly_name: 'WAN bandwidth'
        value_template: "{{ (states('sensor.wan_bandwidth') | int / 1000) | round(2) }}"
        availability_template: >-
          {{ states("sensor.wan_bandwidth") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: "Mbps"
      tautulli_lan_bandwidth:
        friendly_name: 'LAN bandwidth'
        value_template: "{{ (states('sensor.lan_bandwidth') | int / 1000) | round(2) }}"
        availability_template: >-
          {{ states("sensor.lan_bandwidth") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: "Mbps"
      tautulli_total_bandwidth:
        friendly_name: 'Total bandwidth'
        value_template: "{{ (states('sensor.total_bandwidth') | int / 1000) | round(2) }}"
        availability_template: >-
          {{ states("sensor.total_bandwidth") not in ["unknown", "unavailable", "none"] }}
        unit_of_measurement: "Mbps"

Plex card:

elements:
  - style:
      left: 20%
      top: 14%
    text: '<b style=''color: orange; font-size: 13px''>Total </b>'
    type: custom:text-element
  - entity: sensor.tautulli
    style:
      color: white
      font-size: 12px
      left: 20%
      top: 26%
    type: state-label
  - style:
      left: 55%
      top: 14%
    text: '<b style=''color: orange; font-size: 13px''>Direct play </b>'
    type: custom:text-element
  - entity: sensor.direct_plays
    style:
      color: white
      font-size: 12px
      left: 55%
      top: 26%
    type: state-label
  - style:
      left: 20%
      top: 44%
    text: '<b style=''color: orange; font-size: 13px''>Direct stream </b>'
    type: custom:text-element
  - entity: sensor.direct_streams
    style:
      color: white
      font-size: 12px
      left: 20%
      top: 56%
    type: state-label
  - style:
      left: 55%
      text-align: left
      top: 44%
    text: '<b style=''color: orange; font-size: 13px''>Transcode </b>'
    type: custom:text-element
  - entity: sensor.transcodes
    style:
      color: white
      font-size: 12px
      left: 55%
      top: 56%
    type: state-label
  - style:
      left: 20%
      top: 74%
    text: '<b style=''color: orange; font-size: 13px''>LAN bandwidth </b>'
    type: custom:text-element
  - entity: sensor.tautulli_lan_bandwidth
    style:
      color: white
      font-size: 12px
      left: 20%
      top: 86%
    type: state-label
  - style:
      left: 55%
      top: 74%
    text: >-
      <b text-align: left, style='color: orange; font-size: 13px'>WAN bandwidth
      </b>
    type: custom:text-element
  - entity: sensor.tautulli_wan_bandwidth
    style:
      color: white
      font-size: 12px
      left: 55%
      top: 86%
    type: state-label
image: /local/images/plexbanner.png
type: picture-elements

Plex LAN Graph:

align_icon: right
animate: true
entities:
  - entity: sensor.tautulli_lan_bandwidth
font_size: 60
icon: mdi:arrow-down-thick
line_color: orange
line_width: 6
name: LAN
show_fill: true
type: custom:mini-graph-card

Plex WAN Graph:

align_icon: right
animate: true
entities:
  - entity: sensor.tautulli_wan_bandwidth
font_size: 60
icon: mdi:arrow-up-thick
line_color: red
line_width: 6
name: WAN
show_fill: true
type: custom:mini-graph-card
1 Like