Convert uptime in Gas (m³)

Hi, ive created a sensor with uptime of my thermostat.
How i can convert my uptime in m³?

  - platform: history_stats
    name: Uptime Riscaldamento
    entity_id: climate.riscaldamento
    state: "heat_cool"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

This is my sensor, i need a sensor with m³ : get the value of sensor.climate.riscaldamento and multiply for 2.89.

Thank you all

:thinking:
sensor:

  - platform: template
    sensors:    
      newsensor:
        friendly_name: New sensor
        unit_of_measurement:  'm³'
        value_template: "{{ (states('sensor.climate.riscaldamento') | float(0) * 2.89)  | round(1) }}"  

try to add

device_class: energy
1 Like

Nice! It works!
But why i can’t show it in energy → gas consumption panel?
I can choose only energy power consumption.

Sorry but i’m very new of home assistant.

 - platform: template
    sensors:    
      newsensor:
        friendly_name: New sensor
        state_class: 'total_increasing'
        device_class: 'gas'
        unit_of_measurement:  'm³'
        value_template: "{{ (states('sensor.climate.riscaldamento') | float(0) * 2.89)  | round(1) }}"  
1 Like

That won’t work, state_class isn’t available on the legacy template sensor configuraiton.

@DannyGi

template:
- sensor:    
  - unique_id: my_gas_template_sensor
    name: Gas Meter
    state_class: total_increasing
    device_class: gas
    unit_of_measurement: m³
    state: "{{ (states('sensor.climate.riscaldamento') | float(0) * 2.89)  | round(1) }}"
    availability: "{{ states('sensor.climate.riscaldamento') | is_number }}"
2 Likes

Invalid config

The following integrations and platforms could not be set up:

  • template

Error. How i can fix it? Thank you very much guys

remove the s on sensors

1 Like

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

powercalc:
http:
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

api:
alexa:
  smart_home:

frontend:
  themes: !include_dir_merge_named themes

# Example configuration.yaml entry
sensor:
  - platform: history_stats
    name: Uptime Riscaldamento
    entity_id: climate.riscaldamento
    state: "heat_cool"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

template:
  - sensor:
      - unique_id: my_gas_template_sensor
        name: Gas Meter
        state_class: total_increasing
        device_class: gas
        unit_of_measurement: m³
        state: "{{ (states('sensor.uptime_riscaldamento') | float(0) * 2.89)  | round(1) }}"
        availability: "{{ states('sensor.uptime_riscaldamento') | is_number }}"

      - platform: integration
        name: gas_total_consumption
        source: sensor.gas_consumption
        unit_prefix: k
        round: 2

      #Integration:
      - platform: integration
        name: bticino_total_consumption
        source: sensor.consumo_generale_electrical_measurement
        unit_prefix: k
        round: 0

#Utility meter
utility_meter:
  meter_meross1_daily:
    source: sensor.bticino_total_consumption
    cycle: daily

This is my configuration

You borked your configuration. What I posted does not go in or replace the sensor section.

... stufff...

template:
- sensor:    
  - unique_id: my_gas_template_sensor
    name: Gas Meter
    state_class: total_increasing
    device_class: gas
    unit_of_measurement: m³
    state: "{{ (states('sensor.climate.riscaldamento') | float(0) * 2.89)  | round(1) }}"
    availability: "{{ states('sensor.climate.riscaldamento') | is_number }}"

... more stuff ...

sensor: 
- platform: blah
  ... other sensors...
```

Where i paste your code? Sorry but im really newbie

it just pastes inside configuration.yaml as is. it does not replace any existing configuration.

Ive pasted as is under sensor. And it give me error. Dunno

Edit: i’ve clear my code. Its work now! Really thank you

post the config again. Do not alter the code. Just copy/paste. I don’t know how else to spell it to you. Don’t think, just do. Then review after.