Is it possible to add a unit to an undefined RFXTRX sensor?

I have made myself an energy meter (basic blink counter based on an ATTiny85) that transmits as two rfxmeters - for the rfxmeter there seem to be no units defined (which is fine as the protocol is used for power, gas, water and possible others for DIY use), so it shows up as just a number - the state blurbs are:

<state sensor.strmforbruk_kwt=262392; friendly_name=Totalforbruk, icon=mdi:power-plug, Counter value=262392, Rssi numeric=6 @ 2016-08-31T00:04:30.550634+02:00>
<state sensor.momentanforbruk_w=1362; friendly_name=Momentanforbruk, icon=mdi:power-plug, Counter value=1362, Rssi numeric=6 @ 2016-08-31T00:06:30.653589+02:00>

To remedy this I thought I’d try my hand at a sensor template, but somehow the only effect is to remove the sensors altogether from my setup, and of course it spits out an error, seemingly whatever I do.

This is what my latest attempt looks like:

  - platform: template
    sensors:
      strmforbruk_kwt:
        friendly_name: 'Totalforbruk'
        unit_of_measurement: 'kWt'
      momentanforbruk_w:
        friendly_name: 'Momentanforbruk'
        unit_of_measurement: 'W'

Is what I’m trying to do poossible? If so, could anyone give me a pointer as to where I’m going wrong?

Best regards:)

Currently not possible to specify unir of measurement in the rfxtrx sensor, but I can try add it as a option

I’m bad with templates but wouldn’t the following work?

sensor:
  - platform: template
    sensors:
      strmforbruk_kwt_plus_kwt:
        value_template: '{{ sensor.strmforbruk_kwt }}'
        friendly_name: 'Totalforbruk'
        unit_of_measurement: 'W'
1 Like

It would be awesome to have a built-in option to set the unit, although I must admit I finally figured out a bit about how templates work, and have now got this working!

(I hadn’t realized that template sensors are standalone objects that you need to copy values to and give unique names…)

My setup to get this working looks like this:

customize:
sensor.strmforbruk_kwt:
friendly_name: ‘Totalforbruk’
hidden: true
sensor.momentanforbruk_w:
friendly_name: ‘Momentanforbruk’
hidden: true
sensor.strmforbruk_kwt_tmp:
friendly_name: ‘Totalforbruk’
icon: mdi:power-plug
sensor.momentanforbruk_kw:
friendly_name: ‘Momentanforbruk’
icon: mdi:power-plug

sensor:

  • platform: template
    sensors:
    strmforbruk_kwt_tmp:
    friendly_name: ‘Totalforbruk’
    unit_of_measurement: ‘kWt’
    value_template: ‘{{ states.sensor.strmforbruk_kwt.state | int + 64089 }}’
    momentanforbruk_kw:
    friendly_name: ‘Momentanforbruk’
    unit_of_measurement: ‘kW’
    value_template: ‘{{ states.sensor.momentanforbruk_w.state | float / 1000 }}’

The value template for my “Totalforbruk” is just corrected to match the counter on my utility meter, and the other one is / 1000 to convert watt to kilowatt.

Thank you for your help, hope this thread can help someone else out too:)

1 Like