Availability with modbus sensor?

I have several sensors based on modbus. I have gotten errors several times in graph rendering like below image, and I guess this is because modbus uses a default value (0) instead of unavailable? Is there any way to avoid such issues?


I found that there is such a thing as an availability_template but I don’t think that works with modbus?.. Also I’ve looked at the lazy_error_count and set that to 1 but that does not seem to work either…
below is my config for my very basic modbus sensors!

  - name: H60
    type: tcp
    host: 192.168.x.x
    port: xxx
    sensors:
      - name: m_0
        register_type: input
        address: 0

I later use a template to create outdoor and indoor temperature values from m_5 and m_6 which has samt config as m_0.

Here is my template sensor:

  - platform: template
    sensors:
      outdoor_temperature:
        unique_id: sensor.h60_outdoor_temperature
        unit_of_measurement: °C
        value_template: "{{states('sensor.m_5') | float / 10 }}"
        availability_template: >
          {% if is_state("sensor.m_5", "unavailable") %}
            false
          {% elif is_state("sensor.m_5", "unknown") %}
            false
          {% else %}
            true
          {%- endif %}
      indoor_temperature:
        unique_id: sensor.h60_indoor_temperature
        unit_of_measurement: °C
        value_template: "{{states('sensor.m_6') | float / 10 }}"
        availability_template: >
          {% if is_state("sensor.m_5", "unavailable") %}
            false
          {% elif is_state("sensor.m_5", "unknown") %}
            false
          {% else %}
            true
          {%- endif %}

Do the graphs of m_0 and m_1 have the unwanted zeros in them?

Or do they have gaps?

It looks like you have only shown your template sensor graphs.

If it is only an issue with your templates going to zero when the modbus sensors are unknown this can be fixed. Template sensors do have an availability option.

The value goes to 0… I’ve added my template info in the post also!

Well if it is m_0 and m_1 that go to zero there’s not much you can do, unless your temperatures are always above zero.

I’m sorry I miss understood your last question!


It seems that m_5 actually becomes unavailable…
But right after its unavailable it becomes 0 and then later it gets a correct value… The value is always minimum 10 I think because the value should be divided by 10 to get the correct decimal temperature value… so 0 I belive is always incorrect…