Sensor customization issue: no icon change

HI,

have a sensor with possible values 1 (low tariff) or 2 (high)

want to have the icon change depending accordingly, and the color. Color template works fine, icon won’t change.
Anyone spot the error? More-info does show the correct mdi icon…?

sensor.huidig_tarief:
   templates:
     theme: >
      if (state === '1') return 'green'; else return 'orange';
#    icon_template: >
#          {% if (states.sensor.huidig_tarief.state == '1') %} mdi:numeric-1-box-multiple-outline
#          {% elif (states.sensor.huidig_tarief.state == '2') %} mdi:numeric-2-box-multiple-outline
#          {% endif %}
     icon_template: >
            if (state === '1') return 'mdi:numeric-1-box-multiple-outline';
            if (state === '2') return 'mdi:numeric-2-box-multiple-outline';
            else return 'mdi:fire' 

17
54

well, this was easy. In the end.

having tried all possible options documented and seen on the community… (at least, as far as my eyes could spot the differences, I just figured, why not…

took out the _template of icon_template, and what do you know:
47

34

sensor.tarief_daystart:
  templates:
    icon: >
      if (state === '1') return 'mdi:numeric-1-box-multiple-outline';
      else if (state === '2') return 'mdi:numeric-2-box-multiple-outline';
      else return 'mdi:fire';
    theme: >
      if (state === '1') return 'green'; else return 'orange';

Happy camper here…
Cheers,
Marius

Hi Maruis,

Could you maybe tell me how you made the sensor for laagtarief itself ?

I’m a bit of a newbe, but try to make an automation for my waterheater working with heatpump, heatpipes and as a backup 3 kW electric heating rod.

As you would understand, I like to do most on laag tarief.

Kind regards,

Erik
(Dutch)

sure, it is a customization of my sensor.huidig_tarief, which is directly taken from the smart meter (which is connected over Modbus to my Mqtt enabled Z-wave hub…)

sensor:

- platform: mqtt
  state_topic: 'macaddress/energy-dsmr4/id/c_tariff'
  name: 'Huidig Tarief'
 #unit_of_measurement: 'Tarief'

and customization:

homeassistant:
  customize:
    sensor.huidig_tarief:
      templates:
        icon: >
          if (state === '1') return 'mdi:numeric-1-box-multiple-outline';
          if (state === '2') return 'mdi:numeric-2-box-multiple-outline';
          return 'mdi:fire';
        theme: >
          if (state === '1') return 'green';
          return 'orange';
        _stateDisplay: >
           if (state === '1') return 'Laag';
           return 'Hoog';

if you don’t have that, you can always make an automation based on the time the Laag-tarief starts and ends. Might be even simpler :wink:

feel free to adapt this Boiler-switch automation…

  - alias: Boiler switch
    id: 'Boiler switch'
    trigger:
      - platform: state
        entity_id: sensor.huidig_tarief
#      - platform: state
#        entity_id: sensor.zp_actuele_opbrengst
      - platform: state
        entity_id: binary_sensor.zp_opbrengst_threshold_input
    condition:
      - condition: template
        value_template: >
          {{ trigger.to_state.state is not none and
             trigger.from_state.state is not none and
             trigger.to_state.state != trigger.from_state.state }}
#      - condition: template
#        value_template: >
#         {{ states('binary_sensor.zp_opbrengst_threshold_input') in ['on','off'] }}
      - condition: template
        value_template: >
          {{ (as_timestamp(now()) - 
              as_timestamp(state_attr('automation.boiler_switch','last_triggered')) 
              | default(0) | int > 240) }}
      - condition: template
        value_template: >
          {{ states('switch.sw_boiler_bijkeuken_template') != 
             ('on' if is_state('binary_sensor.zp_opbrengst_threshold_input','on') or
                        is_state('sensor.huidig_tarief', '1') 
              else 'off')}}
    action:
      - service_template: >
          switch.turn_{{'on' if is_state('binary_sensor.zp_opbrengst_threshold_input','on') or
                        is_state('sensor.huidig_tarief', '1') else 'off'}}
        entity_id: switch.sw_boiler_bijkeuken_template
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_system', 'on')}}
      - service: notify.notify
        data_template:
          message: >
            Threshold: {{states('binary_sensor.zp_opbrengst_threshold_input')}}, ZP {{states('sensor.zp_actuele_opbrengst')}}, Tarief {{states('sensor.huidig_tarief')}}: 
            Switching Boiler: {{'on' if is_state('binary_sensor.zp_opbrengst_threshold_input','on') or
                       is_state('sensor.huidig_tarief', '1') else 'off' }}.

kicks in when Tarief is Laag, or Solar Production is more than a threshold, in this case set by an input_number used by the binary_sensor. Switches off again when either of the triggers do (enter Hoog tarief or solarprocduction less than threshold)

Thanks,

Only I thought that you had a sensor made that works like a switch for laag tarief or hoog tarief.
Thats what Im actualy looking for.

The part you made with symbols for neither hoog tarief or laag tarief look realy nice

Kind regads,

Erik

What I want to craete at the end is an automation to work with all of de heating devices in my system, but to activate under different surcumstanses.
ie

heatpipes = always
heatpump = weekdays hoog tarief turn on at lower than 40 C turn of at 50 C, low tarief turn on below 50 C turn of at 55
heatingrod = only turn on in laag tarief with a temp below 40 C
heatpump = in the night from sat to sun heat to 60C starting at 21:00, when still nog 60 C at ie 2:00, turn on heatrod as well (legionella prevention 1x a week)

Do you know or I could get that info from a rooted Toon ?

no, I don’t have a Toon let alone a rooted one :wink: check toe forum, there are others that do.

everything else is possible …fairly simple I would say. If you got the right hardware and are able to act on them over HA

Well all is possible I guess, but I like it to do automated as much as possible. No use needing to flip the switch manually if the sensors.switches allow for automation.

That is not really what I menth. a sensor that gives a 0 or 1 or true or false or on or off falleu depending on laag or hoog tarief to use in other automations
to be able to use different settings for laag or hoog tarief

maybe you should start a new thread for this, and describe precisely what you want, then we can try to help you.

Thanks for the sugestion, I just did

1 Like

where?Can’t find it… sorry