Write value to InfluxDB

Hello, I can manually write value to InfluxDB in its own GUI by entering:
settings,name=target_temp value=25 9223372036854775806

Is it possible to accomplish the same by creating HA service? The “25” number would be entity states(input_number.lr_target_temperature)

Thank you, Jan

Why not use the influxdb integration and include the input_number entity?

I did that, but the problem is that the input_number entity is aging and I need it current, because I show it in grafana stats for last 60 minutes. If input_number entity has not been changed for 60 minutes then it disappears from grafana. The solution is either to refresh the input_number entity every 50 min by its own value - which I do not know how to do and nobody here reacted to my question, or make direct insert to InfluxDB with timestamp far in the future. Then it will always show in last 60 minutes.

Hi
because this recent thread I opened helps you, I had the same challenge, using a template sensor with an addtional attribute based on now()

My sample updates automatically every 5 minutes to keep the query in Grafana happy.

Armin

Thanks. Intendation is missing, so I tried to format it correctly, is it like this?

binary_sensor: 
  - platform: template 
    sensors: 
      tbalkontuer: 
        value_template: "{{ states('binary_sensor.balkontuer') }}" 
        friendly_name: "Template Balkontür" 
        device_class: door 
        unique_id: tbalkontuer 
        attribute_templates: 
          update_now: "{{ (now().minute / 5) | round(0) }}"

It is not clear to me why do you use binary sensor if it only can have two states. Ah I understand now, the sensor is switch! :slight_smile:

Thanks, Jan

Thanks, I modified it a bit and it works well!

sensor 26: 
  - platform: template 
    sensors: 
      gr_lr_target_temp: 
        unit_of_measurement: "°C"  
        value_template: "{{ states('input_number.lr_target_temperature') }}" 
        friendly_name: "LR Target temp for grafana" 
        device_class: temperature 
        unique_id: gr_lr_target_temp
        attribute_templates: 
          update_now: "{{ (now().minute / 50) | round(0) }}"      

How about using Grafana’s fill(previous) feature? This does exactly that, no need for some workarounds.

Hi
I use fill(previous) in the Grafana queries in combination with the above configuration, but fill(previous) only helps you if there is at least one row within the timeframe queried and then only fills after(!) this with the previous value
With the template sensors I create an entry in influx every 5 minutes, using statusmap-panels to show history of some binary sensors in Grafana, you still see “no data” at the start of the row, until the time where the first value was stored

Armin