question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to setup a switch template to call some services

See original GitHub issue

Good day ! to begin with, I want to express my deep gratitude to the developers of the add-on , xiaomi_airpurifier , and express hope that the project will continue to develop!

now about the topic of the post:

according to the instructions in README.md I installed the add-on , xiaomi_airpurifier , and set up the Air Humidifier MJJSQ .

Screenshot_2020-10-30-22-22-14-748_com android chrome

after studying the post

https://community.home-assistant.io/t/xiaomi-air-purifier-show-all-sensors-and-switches-in-ui-and-homekit/121786

unsuccessfully trying to add on / off lights, need your help.

here is my configuration.yaml file

fan:
  - platform: xiaomi_miio_airpurifier
    name: Xiaomi Air Humidifier
    host: 192.168.1.191
    token: e23dfbcf44f8aeea9e82d409c9c21e2b
    model: deerma.humidifier.mjjsq

sensor:
  - platform: template
    sensors:
      airpurifier_led:
        friendly_name: Air Purifier led Index
        value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.led }}'
      airhumidifier_temperature:
        friendly_name: Air Humidifier Temperature
        value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.temperature }}'
        unit_of_measurement: '°C'
      airhumidifier_humidity:
        friendly_name: Air Humidifier Humidity
        value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.humidity }}'
        unit_of_measurement: '%'
      airhumidifier_mode:
        friendly_name: Air Humidifier mode
        value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.mode }}'
      airhumidifier_target_humidity:
        friendly_name: Air Humidifier Target Humidity
        value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.target_humidity }}'
        unit_of_measurement: '%'   
      airhumidifier_model:
        friendly_name: Air Humidifier model
        value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.model }}'

here is an example of what I am trying to modify

switch:
  - platform: template
    switches:
      xiaomi_airpurifier_led:
        friendly_name: "LED"
        value_template: "{{ is_state_attr('fan.xiaomi_miio_device', 'led', true) }}"
        turn_on:
          service: xiaomi_miio.fan_set_led_on
          data:
            entity_id: fan.xiaomi_miio_device
        turn_off:
          service: xiaomi_miio.fan_set_led_off
          data:
            entity_id: fan.xiaomi_miio_device
        icon_template: "mdi:lightbulb-outline"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:28 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
syssicommented, Nov 4, 2020

Please try this one:

sensor:
  - platform: template
    sensors:
      airhumidifier_target_humidity:
        friendly_name: Target humidity
        value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.target_humidity }}'
        unit_of_measurement: '%'
        icon_template: mdi:water-percent

input_number:
  airhumidifier_target_humidity:
    name: Target humidity
    min: 0
    max: 99
    step: 1

automation:
  - alias: Select target humidity by slider
    trigger:
      platform: state
      entity_id: input_number.airhumidifier_target_humidity
    action:
      - service: xiaomi_miio_airpurifier.fan_set_target_humidity
        data_template:
          entity_id: fan.xiaomi_air_humidifier
          humidity: '{{ states.input_number.airhumidifier_target_humidity.state|int }}'

  - alias: Monitor target humidity and update slider
    trigger:
      platform: state
      entity_id: sensor.airhumidifier_target_humidity
    action:
      service: input_number.set_value
      entity_id: input_number.airhumidifier_target_humidity
      data_template:
        value: '{{ states.fan.xiaomi_air_humidifier.attributes.target_humidity }}'

The target_humidity attribute is exposed as template sensor here. So we can monitor the state of the sensor.

1reaction
syssicommented, Nov 1, 2020

@4ertik131 The target_humidity is available now if you update the custom component to the develop branch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using a switch to call a service - Home Assistant Community
Instructions on how to setup scripts within Home Assistant. A template switch could also work. Home Assistant. Template Switch.
Read more >
Interface Templates [Cisco IOS 15.2E] - Configuration Guides
Enables multilayer switching configurations. This command is available on the following devices in template configuration mode:.
Read more >
Templates for Switching Best Practices - Cisco Meraki
Create a new switch network. · Add devices to the network as normal. · Navigate to Organization > Configuration templates > Template name....
Read more >
Switching templates in version 7.0 - Squarespace Help Center
This guide covers how to switch templates on version 7.0. ... Some changes that you make to a template preview affect your live...
Read more >
Command-line switches for Microsoft Office products
Make a switch available for reuse by creating a shortcut ... a read-only copy of a document that is stored on a Microsoft...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found