Problems to configure my Oregon sensor

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,

I suggest you explore the Utility Meter integration. You can create a Utility Meter Sensor with cycle: daily to monitor sensor.total_rain.

utility_meter:
  rain_daily:
    source: sensor.total_rain
    cycle: daily

I have a final question:
I recieve km/h on the windsensor and want to have it in m/s.
I guess i can use the Template sensor in some way.
Im not sure how to define(Still learning)
I want to have the new value in a new sensor if its suitable, but if its better to adjust the existing, thats OK,

Divide the speed in km/h by 3.6 to get m/s. Round the result to 2 decimal places.

For example:

- name: 'Average_Speed'
  unique_id: 'Average_Speed'
  state_topic: 'oregon/wind/AvgSpeed'
  unit_of_measurement: 'm/s'
  value_template: '{{ (value_json.AvgSpeed / 3.6) | round(2) }}'

@123 This solution have worked for 8 month now=), but now im getting the error “Error executing script. Service not found for call_service at pos 1: Unable to find service mqtt.publish”
Have the command “call for service” mqqt.publish been taken away from Home assistant?

The mqtt.publish service call is still available.

Ensure you still have the MQTT integration installed and configured properly. Without it, MQTT-related services will not be present.

When running mqtt publish, my HA says “Error rendering data template: UndefinedError: ‘trigger’ is undefined”

In my previous post, I asked that you “ensure you have the MQTT integration installed and configured properly”. What did you do to confirm it’s present and working?

You’ll get that if you attempted to test the automation by executing its Run command.

Reference: Testing your automation

I can see that my MQTT recieves data from the broker, but they dont show in my sensor in home assistant. im using the same code that you sent me.

My actual conig in configuration.yaml:
mqtt:
sensor:
- name: ‘Average_Speed’
unique_id: ‘Average_Speed’
state_topic: ‘oregon/wind/AvgSpeed’
unit_of_measurement: ‘m/s’
value_template: ‘{{ (value_json.AvgSpeed / 3.6) | round(2) }}’

- name: 'Gust_Speed'
  unique_id: 'Gust_Speed'
  state_topic: 'oregon/wind/GustSpeed'
  unit_of_measurement: 'm/s'
  value_template: '{{ (value_json.GustSpeed / 3.6) | round(2) }}'

- name: 'Direction'
  unique_id: 'Direction'
  state_topic: 'oregon/wind/Direction'
  value_template:  >
    {% set directions = 
      { 12: 'Norr',
        35: 'Norr Norr Öst',
        57: 'Norr Öst',
        80: 'Öst Norr Öst',
        102: 'Öst',
        125: 'Öst Syd Öst',
        147: 'Syd Öst',
        170: 'Syd Syd Öst',
        192: 'Syd',
        215: 'Syd Syd Väst',
        237: 'Syd Väst',
        260: 'Väst Syd Väst',
        282: 'Väst',
        305: 'Väst Norr Väst',
        327: 'Norr Väst',
        349: 'Norr Norr Väst',
        360: 'Norr' } %}
    {{ directions.get(directions.keys() | select('>', value_json.Direction | int(0)) | first, 'Unknown') }}
 
- name: 'Current_Rain'
  unique_id: 'Current_Rain'
  state_topic: 'oregon/rain/CurrentRain'
  unit_of_measurement: 'mm/h'
  value_template: '{{ value_json.CurrentRain }}'
  
- name: 'Total_Rain'
  unique_id: 'Total_Rain'
  state_topic: 'oregon/rain/CurrentTRain'
  unit_of_measurement: 'mm'
  value_template: '{{ value_json.CurrentTRain }}'

Here is my automation for the values to the sensor.

alias: Auto-värden till vädersensornerna.
trigger:

  • id: rain
    platform: mqtt
    topic: Vera/Events/3050
  • 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
    mode: queued

I have checked the ids of the units from Vera and its correct , 2880 and 3050

@123 I get these error in my HA logs:

  • Template variable warning: ‘dict object’ has no attribute ‘id’ when rendering ‘oregon/{{ trigger.id }}/{{ trigger.payload_json.Variable }}’
  • Template variable error: ‘dict object’ has no attribute ‘payload_json’ when rendering ‘oregon/{{ trigger.id }}/{{ trigger.payload_json.Variable }}’

Auto-värden till vädersensornerna.: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘payload_json’

Error while executing automation automation.skapa_unika_varden_till_vadersensornerna_2: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘payload_json’

Looks like something wrong in the automation.

If you attempted to test the automation by manually triggering it, using the Run command, you will get those errors. The trigger variable doesn’t exist when you manually trigger the automation. Therefore all of these will be undefined:
trigger.id
trigger.payload_json.Variable

This is what I get when I trigger manually in my phone.