Problems to configure my Oregon sensor

Can someone give me a hint how to present this MQTT data in Home assistant. I have added a sensor.yaml and I have the sensors in Home Assistant, but it says “not a numeric”.
I need to configure the sensor with the command value_template in correct way.
Im totally new for Yaml and learning from here.

I want to have 3 data from a Oregon Windsensor
Gustspeed, Averagespeed, Direction.
I want to have 2 values from a Oregon(PCR800) rainsensor:
Currentrain, Current totalt rain.

Here is my data from the Mqtt:
Meddelande 192 mottaget på Vera/Events/2879 vid 12:30 :
{
“CurrentRain”: 107.08,
“DeviceId”: 2879,
“DeviceName”: “Regnsensor 220403”,
“DeviceType”: “urn:schemas-micasaverde-com:device:RainSensor:1”,
“OldCurrentRain”: 200.45,
“RoomId”: 14,
“RoomName”: “Utomhus”,
“ServiceId”: “urn:upnp-org:serviceId:RainSensor1”,
“Time”: 1659695454,
“Variable”: “CurrentRain”
}
QoS: 0 - Retain: false
Meddelande 191 mottaget på Vera/Events/2879 vid 12:30 :
{
“CurrentTRain”: 326.8,
“DeviceId”: 2879,
“DeviceName”: “Regnsensor 220403”,
“DeviceType”: “urn:schemas-micasaverde-com:device:RainSensor:1”,
“OldCurrentTRain”: 302.4,
“RoomId”: 14,
“RoomName”: “Utomhus”,
“ServiceId”: “urn:upnp-org:serviceId:RainSensor1”,
“Time”: 1659695454,
“Variable”: “CurrentTRain”
}
QoS: 0 - Retain: false
Meddelande 45 mottaget på Vera/Events/2880 vid 11:40 :
{
“DeviceId”: 2880,
“DeviceName”: “Vindsensor 220403”,
“DeviceType”: “urn:schemas-micasaverde-com:device:WindSensor:1”,
“GustSpeed”: 4,
“OldGustSpeed”: 6,
“RoomId”: 14,
“RoomName”: “Utomhus”,
“ServiceId”: “urn:upnp-org:serviceId:WindSensor1”,
“Time”: 1659778819,
“Variable”: “GustSpeed”
}
QoS: 0 - Retain: false
Meddelande 44 mottaget på Vera/Events/2880 vid 11:40 :
{
“AvgSpeed”: 6,
“DeviceId”: 2880,
“DeviceName”: “Vindsensor 220403”,
“DeviceType”: “urn:schemas-micasaverde-com:device:WindSensor:1”,
“OldAvgSpeed”: 7,
“RoomId”: 14,
“RoomName”: “Utomhus”,
“ServiceId”: “urn:upnp-org:serviceId:WindSensor1”,
“Time”: 1659778819,
“Variable”: “AvgSpeed”
}
QoS: 0 - Retain: false
Meddelande 43 mottaget på Vera/Events/2880 vid 11:40 :
{
“DeviceId”: 2880,
“DeviceName”: “Vindsensor 220403”,
“DeviceType”: “urn:schemas-micasaverde-com:device:WindSensor:1”,
“Direction”: 225,
“OldDirection”: 292,
“RoomId”: 14,
“RoomName”: “Utomhus”,
“ServiceId”: “urn:upnp-org:serviceId:WindSensor1”,
“Time”: 1659778819,
“Variable”: “Direction”
}

HERE IS MY CURRENT Sensor.YAML:

  • platform: mqtt

    state_topic: “#”

    name: “AverageSpeed”

    unique_id: Average_Speed

    unit_of_measurement: ‘m/s’

    value_template: “{{ input_number.AverageSpeed | float }}”

  • platform: mqtt

    state_topic: “#”

    name: “GustSpeed”

    unique_id: Gust_speed

    unit_of_measurement: ‘m/s’

    value_template: “{{ input_number.GustSpeed | float }}”

  • platform: mqtt

    state_topic: “#”

    name: “Direction”

    unique_id: Direction

    value_template: “{{ input_number.Direction | float }}”

  • platform: mqtt

    state_topic: “#”

    name: “Current_Rain”

    unique_id: Current_Rain

    value_template: “{{ input_number.Current_Rain | float }}”

  • platform: mqtt

    state_topic: “#”

    name: “Total_Rain”

    unique_id: Total_Rain

    value_template: “{{ input_number.Total_Rain | float }}”

This what I see
image

Based on the examples you have shown for the received data, an MQTT topic can receive data for more than one sensor. For example, Vera/Events/2880 can receive data for Direction, AvgSpeed, or GustSpeed. In other words, the topic has multiplexed data (i.e. one topic can represent multiple sensors and the received data’s structure can vary).

For this reason, I recommend that you create the following automation which de-multiplexes the received data and forwards it to unique MQTT topics. This will make it easier to configure the five MQTT Sensors because each sensor will receive data via its own MQTT topic.

alias: Oregon Sensor Demultiplexer
mode: queued
trigger:
  - id: 'rain'
    platform: mqtt
    topic: Vera/Events/2879
  - id: 'wind'
    platform: mqtt
    topic: Vera/Events/2880
condition: []
action:
  - service: mqtt.publish
    data:
      topic: 'oregon/{{ trigger.id }}/{{ trigger.payload_json.Variable }}'
      payload: '{{ trigger.payload_json | to_json }}'
      retain: true

The format for configuring MQTT Sensors has changed (the way you defined them has been deprecated and, in a future version, will become invalid). Here is the new format:

mqtt:
  sensor:
    - name: 'Average_Speed'
      unique_id: 'Average_Speed'
      state_topic: 'oregon/wind/AvgSpeed'
      unit_of_measurement: 'm/s'
      value_template: '{{ value_json.AvgSpeed }}'
    - name: 'Gust_Speed'
      unique_id: 'Gust_Speed'
      state_topic: 'oregon/wind/GustSpeed'
      unit_of_measurement: 'm/s'
      value_template: '{{ value_json.GustSpeed }}'
    - name: 'Direction'
      unique_id: 'Direction'
      state_topic: 'oregon/wind/Direction'
      value_template: '{{ value_json.Direction }}'
    - name: 'Current_Rain'
      unique_id: 'Current_Rain'
      state_topic: 'oregon/rain/CurrentRain'
      value_template: '{{ value_json.CurrentRain }}'
    - name: 'Total_Rain'
      unique_id: 'Total_Rain'
      state_topic: 'oregon/rain/CurrentTRain'
      value_template: '{{ value_json.CurrentTRain }}'

Do not copy-paste the example of the new MQTT Sensors into your sensors.yaml file. Put it into your configuration.yaml file (or into mqtt.yaml but only if you have mqtt: !include mqtt.yaml in your configuration.yaml file).

NOTE

It isn’t necessary to use the float filter for any of the received numeric values.

EDIT #1

Correction. Replaced value_json with trigger.payload_json in the automation’s service call.

EDIT #2

Correction. Added to_json filter to automation’s service call.

Thank you so much for your time. @123
I have done exactly as I described but still got no values.
I got some alarm for the last part of the automation, that it couldnt be shown in the visual editor.
Is that a sign of something wrong edited by me?
I took away the forwarding from configuration.yaml to the sensors.yaml.
I put this in the configuration.yaml and can see the new sensors in Ha:

mqtt:
sensor:
- name: ‘Average_Speed’
unique_id: ‘Average_Speed’
state_topic: ‘oregon/wind/AvgSpeed’
unit_of_measurement: ‘m/s’
value_template: ‘{{ value_json.AvgSpeed }}’
- name: ‘Gust_Speed’
unique_id: ‘Gust_Speed’
state_topic: ‘oregon/wind/GustSpeed’
unit_of_measurement: ‘m/s’
value_template: ‘{{ value_json.GustSpeed }}’
- name: ‘Direction’
unique_id: ‘Direction’
state_topic: ‘oregon/wind/Direction’
value_template: ‘{{ value_json.Direction }}’
- name: ‘Current_Rain’
unique_id: ‘Current_Rain’
state_topic: ‘oregon/rain/CurrentRain’
value_template: ‘{{ value_json.CurrentRain }}’
- name: ‘Total_Rain’
unique_id: ‘Total_Rain’
state_topic: ‘oregon/rain/CurrentTRain’
value_template: ‘{{ value_json.CurrentTRain }}’

This is how my configuration now looks like:

mqtt:

sensor:

- name: 'Average_Speed'
  unique_id: 'Average_Speed'
  state_topic: 'oregon/wind/AvgSpeed'
  unit_of_measurement: 'm/s'
  value_template: '{{ value_json.AvgSpeed }}'

- name: 'Gust_Speed'
  unique_id: 'Gust_Speed'
  state_topic: 'oregon/wind/GustSpeed'
  unit_of_measurement: 'm/s'
  value_template: '{{ value_json.GustSpeed }}'
- name: 'Direction'
  unique_id: 'Direction'
  state_topic: 'oregon/wind/Direction'
  value_template: '{{ value_json.Direction }}'

- name: 'Current_Rain'
  unique_id: 'Current_Rain'
  state_topic: 'oregon/rain/CurrentRain'
  value_template: '{{ value_json.CurrentRain }}'

- name: 'Total_Rain'
  unique_id: 'Total_Rain'
  state_topic: 'oregon/rain/CurrentTRain'
  value_template: '{{ value_json.CurrentTRain }}'

Results:
image

This the error I get in the automation.
Error: Error rendering data template: UndefinedError: ‘value_json’ is undefined

The code for the action are here:

service: mqtt.publish
data:
topic: oregon/{{ trigger.id }}/{{ value_json.Variable }}
payload: ‘{{ value_json }}’
retain: true

@123 Do you have any ideea? Can I split all variables in 6 different rules just to make it straight forward or do you know why I get that error message?

I made a mistake in the automation’s service call and have corrected the posted example (see above). Basically, replace value_json with trigger.payload_json in the automation’s service call.

Thanks, now the automation runs through, but now i get the same data,but in one row.
How to connect eg. Average_Speed to the sensor?
How to pick out only one value and dedicate that to the sensor?
I guess we are close now?

image

The “connection” is performed by the MQTT Sensor’s state_topic.

mqtt:
  sensor:
    - name: 'Average_Speed'
      unique_id: 'Average_Speed'
      state_topic: 'oregon/wind/AvgSpeed'
      unit_of_measurement: 'm/s'
      value_template: '{{ value_json.AvgSpeed }}'

The MQTT Sensor receives the payload via oregon/wind/AvgSpeed and then uses the value of the AvgSpeed key.

but, I have done like you showed me ??
in configuration.yaml

image

And here is my automation in edited version.

image

I can see that from the second screenshot you posted which contains the five MQTT Sensors. The sensor values will be updated only when a payload is received (from Vera).

Check the log for any warnings or errors that may be related to sensor.average_speed.

It looks fine because your previous screenshot clearly shows that the automation is publishing data to oregon/wind/AvgSpeed.

I get data from the windsensor every 10-20sec.
image

That’s also evident from your previous screenshot which showed three payloads published to oregon/wind/AvgSpeed and all were received almost within the same minute.

If the value of sensor.average_speed remains unchanged at zero then you should check the log for errors.

I have an idea of what might be causing the problem.

The payload received by the sensor is not handled as a JSON dictionary. That’s why you are seeing it displayed on a single line (you mentioned that in your previous post). As a consequence, the sensor’s template fails to work because it assumes the received payload is a JSON dictionary (but it isn’t)

Add the to_json filter to the automation’s service call.

  - service: mqtt.publish
    data:
      topic: 'oregon/{{ trigger.id }}/{{ trigger.payload_json.Variable }}'
      payload: '{{ trigger.payload_json | to_json }}'
      retain: true

After you do that, check the appearance of the payload that’s published to oregon/wind/AvgSpeed. It should appear on multiple lines as opposed to a single line. It should be identical to the payload published to Vera/Events/2880

According to your reply via Private Message, the addition of to_json fixed the issue and it now works correctly.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.


You had also asked if there is a way for the Direction sensor to report descriptively as opposed to numerically. Here’s what I suggest:

    - name: 'Direction'
      unique_id: 'Direction'
      state_topic: 'oregon/wind/Direction'
      value_template: >
        {% set directions = 
          { 12: 'North',
            35: 'North North East',
            57: 'North East',
            80: 'East North East',
            102: 'East',
            125: 'East South East',
            147: 'South East',
            170: 'South South East',
            192: 'South',
            215: 'South South West',
            237: 'South West',
            260: 'West South West',
            282: 'West',
            305: 'West North West',
            327: 'North West',
            349: 'North North West',
            360: 'North' } %}
        {{ directions.get(directions.keys() | select('>', value_json.Direction | int(0)) | first, 'Unknown') }}
1 Like

The solution for the direction definitions worked perfect.
You are brilliant. =)
Any ideeas how to track the amount of rain/day with the currentTrain sensor.
Now it accumulates for ever. total amount.
You can see how it accumulates for ever.
“CurrentTRain”: 326.8,
“DeviceId”: 2879,
“DeviceName”: “Regnsensor 220403”,
“DeviceType”: “urn:schemas-micasaverde-com:device:RainSensor:1”,
“OldCurrentTRain”: 302.4,