Output value adjustment

I’d like to be able to adjust a value from a sensor so the adjusted value or something else like a message is displayed.
I use PVOutput to upload lots of energy data too then I link it into HA. I know how to implement rules in PVOutput but not in HA.
My 1st example
PVOuput does not plot data when the figure is 0, so I get a rule to change any 0’s to 1’s. I monitor the energy usage of a fan which displays 1 when not running in HA, I would like to be about to tell HA to change a 1 to a 0 (a reverse of what PVO does) or possibly even better would be to say “FAN OFF” when HA sees 1.
Below is one of my sensors where I’m guessing I can add some configuration data

  - platform: pvoutput
    system_id: xxxxx
    name: wood_burner_fan 
    api_key: xxxxxxxxxxxxxxxxxxxxxxxxxx
    scan_interval: 150
  - platform: template
    sensors:
     power_consumption5:
       value_template: '{% if is_state_attr("sensor.wood_burner_fan", "power_consumption", "NaN") %}0{% else %}{{ state_attr(''sensor.wood_burner_fan'', ''power_consumption'') }}{% endif %}'
       friendly_name: 'Wood Burner Fan Electricity Using'
       unit_of_measurement: 'Watt'
     energy_consumption5:
       value_template: '{{ "%0.1f"|format(state_attr(''sensor.wood_burner_fan'', ''energy_consumption'')|float/1000) }} {{ "%0f"|format(state_attr(''sensor.wood_burner_fan'', ''energy_consumption'')|float+1) }}'
       friendly_name: 'Wood Burner Fan Electricity Used'
       unit_of_measurement: 'kWh'```

Rather than changing 0 to 1 can you add 1 to all readings?

It would be very simple to subtract 1 from the incoming readings.

That wouldn’t achieve what I’m after (I don’t think!) but thanks for the suggestion

Which sensor above are you trying to reformat?

Which sensor above are you trying to reformat?

  - platform: pvoutput
    system_id: xxxxx
    name: wood_burner_fan 
    api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    scan_interval: 150
  - platform: template
    sensors:
     power_consumption5:
       value_template: '{% if is_state_attr("sensor.wood_burner_fan", "power_consumption", "NaN") %}0{% else %}{{ state_attr(''sensor.wood_burner_fan'', ''power_consumption'') }}{% endif %}'
       friendly_name: 'Wood Burner Fan Electricity Using'
       unit_of_measurement: 'Watt'```

Wood Burner Fan Electricity "Using". I would like to add some code that if the output is 1 then make it 0 or say OFF.
- platform: template
  sensors:
    power_consumption5:
      value_template: >
        {% if is_state_attr("sensor.wood_burner_fan", "power_consumption", "NaN") or is_state_attr("sensor.wood_burner_fan", "power_consumption", "1") %}
          OFF
        {% else %}
          {{ state_attr(''sensor.wood_burner_fan'', ''power_consumption'') }}
        {% endif %}'
       friendly_name: 'Wood Burner Fan Electricity Using'
       unit_of_measurement: 'Watt'

Or something close to that since I don’t exactly know how your sensors report.

Thanks finity, I tried that but it came back with a lot of errors in check config, I then tries to correct the errors but just created more :cry:

Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘,’, got ‘sensor’) for dictionary value @ data[‘sensors’][‘power_consumption5’][‘value_template’]. Got ‘{% if is_state_attr(“sensor.wood_burner_fan”, “power_consumption”, “NaN”) or is_state_attr(“sensor.wood_burner_fan”, “power_consumption”, “1”) %}\n OFF\n{% else %}\n {{ state_attr(’‘sensor.wood_burner_fan’’, ‘‘power_consumption’’) }}\n{% endif %}’\n’. (See ?, line ?). Please check the docs at https://home-assistant.io/integrations/sensor.template/

You were right it was close, it did only need a very slight adjustment, thankyou!

       value_template: ' {% if is_state_attr("sensor.wood_burner_fan", "power_consumption", "NaN") or is_state_attr("sensor.wood_burner_fan", "power_consumption", "1") %} OFF {% else %} {{ state_attr(''sensor.wood_burner_fan'', ''power_consumption'') }} {% endif %}'
       friendly_name: 'Wood Burner Fan Electricity Using'
       unit_of_measurement: 'Watt'```

Not quite perfect though as when message shows "OFF" it actually shows "OFF watt", would there be any way of removing the word watt but only when OFF

You could remove the unit of measurement line and code the units into your template.

{% else %} 
  {{ state_attr(''sensor.wood_burner_fan'', ''power_consumption'') }} Watts
{% endif %}