joBr99 / nspanel-lovelace-ui

Custom Firmware for NsPanel with the design of HomeAssistant's lovelace UI in mind, works with Tasmota.
GNU General Public License v3.0
863 stars 187 forks source link

[Feature Request] Fan Control #175

Closed jcs2812 closed 2 years ago

jcs2812 commented 2 years ago

Hi. Is it possible to add fan controls or add a page for fans? I have Sonoff iFan3's running Esphome.

1790fa5a-f49f-4bd5-994e-a174f06153f3 027391e8-050b-4005-8339-a830609bcf51 .

joBr99 commented 2 years ago

You can configure an input_number and some automations to control your fan until there is native support for fans.

https://www.home-assistant.io/integrations/input_number/

jcs2812 commented 2 years ago

Thanks

joBr99 commented 2 years ago

@kroon040

fans should now be displayed as a slider on the entities page, but I don't have a fan to test with

(please also test what happens if the fan is in state off and you are changeing the speed)

Update your app in HACS to main and restart AppDaemon, you don't need to do the firmware update to test this feature

https://github.com/joBr99/nspanel-lovelace-ui#how-to-upgrade-from-a-release-to-the-current-development-version

kroon040 commented 2 years ago

I don't have fans, so I can't test.

joBr99 commented 2 years ago

ups, wanted to mention @jcs2812

jcs2812 commented 2 years ago

@joBr99 I'm getting a blank screen when I add the fan to any entities page, the navigation arrows on top are also gone. Steps used to test. 1 Stopped Appdaemon 2 Updated nspanel-lovlage-ui in HACS to latest 'MAIN" 3 Start Appdaemon 4 Add fan to Entities Card ` - type: cardEntities entities:

5 Add fan to existing Entities Card ` - type: cardEntities entities:

6 Flashed the display with latest tft with Tasmota comand (FlashNextion http://nspanel.pky.eu/lui-us-p-release.tft) I also tried with a local tft upload with the latest copy downloaded from gidhub. (FlashNextion http://192.168.0.200:8123/local/nspanel_US_P.tft) Result, black screen when I navigate to any of the above pages.

Thanks for working on this request, it is highly appreciated Chris

joBr99 commented 2 years ago

hey, can you check the appdaemon log for erros?

joBr99 commented 2 years ago

also try to change L186 / update to main again and restart appdaemon, this might be the issue

https://github.com/joBr99/nspanel-lovelace-ui/commit/ea7b2ae09d870d2ba931ab9ef9283f86907d53d5

jcs2812 commented 2 years ago

Sorry should have checked that.

_2022-05-07 09:40:15.144063 WARNING nspanel-1: Traceback (most recent call last): File "/usr/lib/python3.9/site-packages/appdaemon/threading.py", line 950, in worker funcref(args["event"], data, self.AD.events.sanitize_event_kwargs(app, args["kwargs"])) File "/config/appdaemon/apps/nspanel-lovelace-ui/luibackend/mqttListener.py", line 58, in mqtt_event_callback self._controller.button_press(entity_id, btype, value) File "/config/appdaemon/apps/nspanel-lovelace-ui/luibackend/controller.py", line 168, in button_press self._pages_gen.render_card(card) File "/config/appdaemon/apps/nspanel-lovelace-ui/luibackend/pages.py", line 366, in render_card self.generate_entities_page(navigation, card.title, card.entities) File "/config/appdaemon/apps/nspanel-lovelace-ui/luibackend/pages.py", line 197, in generate_entities_page command += self.generate_entities_item(item) File "/config/appdaemon/apps/nspanel-lovelace-ui/luibackend/pages.py", line 186, in generate_entities_item return f"~number~{entityId}~{iconid}~17299~{name}~{entity.percentage}|0|100" AttributeError: 'Entity' object has no attribute 'percentage' 2022-05-07 09:40:15.153925 WARNING nspanel-1: ------------------------------------------------------------

The fan does have an attribute percentage.

joBr99 commented 2 years ago

changed the line from entity.percentage to entity.attributes.percentage, try again with this change

jcs2812 commented 2 years ago

That worked.... Fantastic When the slider is in 0 the fan switch off, 33 66 and 100 works as it should. Is it possible for the fan icon the change colour then the fan is on? is it possible to increase the length of the slider the 66% and 100% is almost the same spot. IMG_20220507_101436 IMG_20220507_101426

joBr99 commented 2 years ago

is the "on" state of the fan entity really "on" or something specific?

if the state of the fan is "on", this change should work :)

joBr99 commented 2 years ago

@jmbinette

This is an error in the US-P Version, the slider should not overlap with the number.

image

joBr99 commented 2 years ago

@jcs2812 I've updated the position of the slider in the us-p version, run the following command in your tasmota console: FlashNextion http://nspanel.pky.eu/lui-us-p.tft

jcs2812 commented 2 years ago

62f2adf4-ae74-499e-ba80-c12a171c0341 a99e481e-2bdb-44c7-93b4-ae8fe9f2b94c

joBr99 commented 2 years ago

035f03f should fix the color and https://github.com/joBr99/nspanel-lovelace-ui/commit/843828eeb7b973822d8ed08dcee92d8ad6ca1f95 should fix the slider

jcs2812 commented 2 years ago

I'm getting errors now. update tft and AppDaemon. ![Uploading IMG_20220507_111848.jpg…]() 897eb1ec-60f0-44b0-864a-02e7b30edfcb

joBr99 commented 2 years ago

sometimes hacs downloads the latest release instead of main, make sure to wait until it finished loading in the redownload dialog, before clicking download

jcs2812 commented 2 years ago

Thanks, that worked. Everything works on the slider. Is it possible to turn the fan on or off by clicking on the fan icon? Nice to have

joBr99 commented 2 years ago

no, the icons don't have an click action and are overlapped with the touch area to open the detail pages for lights and shutters

jcs2812 commented 2 years ago

Thanks a lot. Wife is happy.:-)

jmbinette commented 2 years ago

@jcs2812 I've updated the position of the slider in the us-p version, run the following command in your tasmota console: FlashNextion http://nspanel.pky.eu/lui-us-p.tft

Thank you !

ljmellor commented 1 year ago

Hi, I have a similar query regarding using the grid page to control fan speeds. I've got 4 buttons set-up, each runs a script to adjust the percentage of the fan. I can't for the life of me get these to change colour when each one is active however, was my approach of using scripts wrong?

Here's my config/scripts;

apps.yaml

---
nspanel-1:
  module: nspanel-lovelace-ui
  class: NsPanelLovelaceUIManager
  config:
    panelRecvTopic: "tele/bedroom_nspanel/RESULT"
    panelSendTopic: "cmnd/bedroom_nspanel/CustomSend"
    locale: "en_GB"
    screensaver:
      entity: weather.home
      autoWeather: true
      weatherOverrideForecast4:
        entity: sensor.bedroom_real_temp
        name: "Temp"
        icon: mdi:thermometer-lines
    sleepBrightness:
      - time: "07:30:00"
        value: 1
      - time: "20:30:00"
        value: 1
    screenBrightness:
      - time: "07:30:00"
        value: 20
      - time: "20:30:00"
        value: 1
    defaultBackgroundColor: "black"
    cards:
      - type: cardGrid
        title: Bedroom
        entities:
          - entity: light.bedroom_lights
            icon: mdi:ceiling-light
          - entity: script.bedroom_off
            color: [255, 0, 0]
            icon: mdi:power
          - entity: script.bedroom_fan_speed_0
            name: "Off"
            icon: mdi:fan-off
          - entity: script.bedroom_fan_speed_1
            name: 1
            icon: mdi:fan-speed-1
          - entity: script.bedroom_fan_speed_2
            name: 2
            icon: mdi:fan-speed-2
          - entity: script.bedroom_fan_speed_3
            name: 3
            icon: mdi:fan-speed-3`

script.bedroom_fan_speed_0

alias: Bedroom Fan Speed 0
sequence:
  - service: fan.set_percentage
    data:
      percentage: 0
    target:
      device_id: bef721ab95e94f1b64a5c22436c4d8d7
mode: single
icon: mdi:fan-minus`

script.bedroom_fan_speed_1

alias: Bedroom Fan Speed 1
sequence:
  - service: fan.set_percentage
    data:
      percentage: 33
    target:
      device_id: bef721ab95e94f1b64a5c22436c4d8d7
mode: single
icon: mdi:fan-speed-1
joBr99 commented 1 year ago

Well, the script is only active for a really short period of time when the script runs. I don't think that there is much you can do about this.

In the latest development version you can open a separate popup for fans similar to the popup for covers and lights. (release has a bug on the fan page)

ljmellor commented 1 year ago

I'm trying to avoid extra steps as it stands to keep it as simple as possible, hence my single button per speed (there's not much smart stuff in the house, yet). Appreciate you getting back to me, it's a very smart looking system that you've created and I'm very impressed. I'm trying to learn bits as I go along so that I may be able to offer some assistance in the future since I'm a web developer at heart, though my knowledge lies mostly in php and javascript/jquery.

joBr99 commented 1 year ago

I guess your best option is to create a template switch for each speed in Homeassistent and use this instead of a script. This should give you the option to have a state.

https://www.home-assistant.io/integrations/switch.template/

joBr99 commented 1 year ago

let me know if you have issues creating the template, then I will try get you an example for a fan

ljmellor commented 1 year ago

I do seem to be a little lost at present, I found one online which looks as follows after I removed the unnecessary oscillate modes, I should probably mention that this is a Sonoff ifan04-H through MQTT...

configuration.yaml addition fan: !include fantemplates.yaml

fantemplates.yaml

# Example configuration.yaml entry
#fan:
  - platform: template
    fans:
      bedroom_fan:
        friendly_name: "Bedroom fan"
        value_template: "{{ states('input_boolean.state') }}"
        percentage_template: "{{ states('input_number.percentage') }}"
        preset_mode_template: "{{ states('input_select.preset_mode') }}"
        oscillating_template: "{{ states('input_select.osc') }}"
        direction_template: "{{ states('input_select.direction') }}"
        turn_on:
          service: script.fan_on
        turn_off:
          service: script.fan_off
        set_percentage:
          service: script.fan_set_speed
          data:
            percentage: "{{ percentage }}"
        set_preset_mode:
          service: script.fans_set_preset_mode
          data:
            preset_mode: "{{ preset_mode }}"
        speed_count: 3
        preset_modes:
          - 'low'
          - 'med'
          - 'max'`

I've not looked very far into it as it stands, I'm still green around the gills where yaml and home assistant are concerned but I'm eager to learn and develop my skills.

joBr99 commented 1 year ago

I tought about something like this, note that this is untested.

switch:
  - platform: template
    switches:
      bedroom_fan_speed_1:
        value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 33) }}"
        turn_on:
          service: fan.set_percentage
          target:
            entity_id: fan.bedroom_fan
            data:
              percentage: 33
        turn_off:
          service: fan.turn_off
          target:
            entity_id: fan.bedroom_fan

      bedroom_fan_speed_2:
        value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 66) }}"
        turn_on:
          service: fan.set_percentage
          target:
            entity_id: fan.bedroom_fan
            data:
              percentage: 66
        turn_off:
          service: fan.turn_off
          target:
            entity_id: fan.bedroom_fan

You cannot put this into your fantemplates.yaml since this is under the switch domain and not in the fan domain, put it into your configuration.yaml or create a seperate file for it like you did for the fan.

ljmellor commented 1 year ago

I'm afraid that after much playing, I'm still a little lost. Getting this error when I validate my yaml now...

Invalid config for [switch.template]: [data] is an invalid option for [switch.template]. Check: switch.template->switches->bedroom_fan_speed_1->turn_on->0->target->data. (See ?, line ?).

My code at present (separate include on the switch domain)...

- platform: template
  switches:
    bedroom_fan_speed_1:
      value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 33) }}"
      turn_on:
        service: fan.set_percentage
        target:
          entity_id: fan.bedroom_fan
          data:
            percentage: 33
      turn_off:
        service: fan.turn_off
        target:
          entity_id: fan.bedroom_fan

    bedroom_fan_speed_2:
      value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 66) }}"
      turn_on:
        service: fan.set_percentage
        target:
          entity_id: fan.bedroom_fan
          data:
            percentage: 66
      turn_off:
        service: fan.turn_off
        target:
          entity_id: fan.bedroom_fan

    bedroom_fan_speed_3:
      value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 100) }}"
      turn_on:
        service: fan.set_percentage
        target:
          entity_id: fan.bedroom_fan
          data:
            percentage: 100
      turn_off:
        service: fan.turn_off
        target:
          entity_id: fan.bedroom_fan

Also, you may notice that I've also learned how to format code blocks in comments as a side effect to this learning.

ljmellor commented 1 year ago

Cracked it, simple case of indentation. Here's where I wound up...

- platform: template
  switches:
    bedroom_fan_speed_1:
      value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 33) }}"
      turn_on:
        service: fan.set_percentage
        target:
          entity_id: fan.bedroom_fan
        data:
          percentage: 33
      turn_off:
        service: fan.turn_off
        target:
          entity_id: fan.bedroom_fan

    bedroom_fan_speed_2:
      value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 66) }}"
      turn_on:
        service: fan.set_percentage
        target:
          entity_id: fan.bedroom_fan
        data:
          percentage: 66
      turn_off:
        service: fan.turn_off
        target:
          entity_id: fan.bedroom_fan

    bedroom_fan_speed_3:
      value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 100) }}"
      turn_on:
        service: fan.set_percentage
        target:
          entity_id: fan.bedroom_fan
        data:
          percentage: 100
      turn_off:
        service: fan.turn_off
        target:
          entity_id: fan.bedroom_fan
joBr99 commented 1 year ago

yes, the example in the homeassistant docs also has data on the same level with target, makes sense

erugaman commented 1 year ago

https://github.com/joBr99/nspanel-lovelace-ui/issues/315#issuecomment-1168986520

Here is a template for FAN using mqtt

———————————————————

El El lun, 29 de agosto de 2022 a la(s) 15:14, Johannes < @.***> escribió:

I tought about something like this, note that this is untested.

switch:

  • platform: template switches: bedroom_fan_speed_1: value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 33) }}" turn_on: service: fan.set_percentage target: entity_id: fan.bedroom_fan data: percentage: 33 turn_off: service: fan.turn_off target: entity_id: fan.bedroom_fan
  • platform: template switches: bedroom_fan_speed_2: value_template: "{{ is_state_attr('fan.bedroom_fan', 'percentage', 66) }}" turn_on: service: fan.set_percentage target: entity_id: fan.bedroom_fan data: percentage: 66 turn_off: service: fan.turn_off target: entity_id: fan.bedroom_fan

— Reply to this email directly, view it on GitHub https://github.com/joBr99/nspanel-lovelace-ui/issues/175#issuecomment-1230812465, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANC72GHAJ4Q4NJAWO432TBLV3UK2XANCNFSM5U2CV4OA . You are receiving this because you commented.Message ID: @.***>

-- Enviado desde mi iPhone