i get the following error about the switch function:
2020-04-03 21:08:17 ERROR (MainThread) [homeassistant.components.rest.switch] Got non-ok response from resource: 405
By specifying username/password in the config, it will already do the authentication:basic for you. It might be messing it up with you specifying it again in the headers section. Especially since the header would need the password encoded following it.
Just a guess.
Also, I recommend using the secrets file. Especially for cases like this
Then, your config would just look like this (no need to filter out uname/password anymore)
Thanks for your help. I tried your advise. First of all the !secret feature is very cool.
but with the following switch function i still get an error code:
Thx for sharing your progress with the Smart-Me Switch.
I was trying to add an additional curl request in the command_state and jquery for the SwitchOn value in the json array so Home Assistant would not offer an on and off switch.
I am pretty new to all this and seem to miss something
I donât think you can access the return code. Actually, I think the variable âvalueâ will be the return code.
Does your command return literal âtrueâ on success? Either way, the special variables used for most all rest/command/etc things are âvalueâ, or âvalue_jsonâ (which just attempts to return âvalueâ as a json object instead of a string.
thx for your answer. I found another way to make it work with the sensor where SwitchOn Value was allready readable. Even if the representation switch on the dashboard acts a little slow. Still better instead of having On and Off Switch separated :slightly_smiling
But value_template is redundant in this case. The state of the sensor is the command_stateâŚunless you specify value_template. Then, it will take the command_state, and run it through the template.
Unless âsensor.smartmeterswitchonâ is a different switch completely, then disregard! Your solution would be correct in that case!
hmmm this is confusing. The command_line how to says that I only can use the state when the value would be 0 (but for Smart-Me it is true or false. Therefore I added the value_template and just gave the command_state a valid value which would be ignored because of the value_template anyway
command_state
(string)(Optional)
If given, this command will be run. Returning a result code 0 will indicate that the switch is on.
value_template
(string)(Optional)
If specified, command_state will ignore the result code of the command but the template evaluating to true will indicate the switch is on.
PS: I only have on SmartMe Switch which I also use as the sensor.
You might have missed my edit. I think I assumed âsensor.smartmeterswitchonâ was the name of this command line switch.
So yeah, give it a dummy command to run and specify a value_template looking at another thing. That will work just fine!! âŚI think!
By doing it your way, your state changes are going to be delayed by the polling interval. Youâll have to wait until this integration decides to run the command_state command again to read the sensor value. Luckily, whenever you toggle this switch, it forces an update. So you might not notice it until you try to control this switch from another source that isnât this integration. But if there is no way to turn this light on otherwise (physical wall button), youâll never even notice!
If you do notice, or want to change it, A template switch will be able to be update realtime.
switch:
- platform: template
switches:
smart_me:
# State of this switch follows this sensor
value_template: "{{ states('sensor.smartmeterswitchon') }}"
turn_on:
service: switch.turn_on
data:
entity_id: switch.smartmeswitch
turn_off:
service: switch.turn_off
data:
entity_id: switch.smartmeswitch
Now you have a switch that runs the right on/off commands and has a state value that is update IMMEDIATELY when sensor.smartmeterswitchon is updated from anywhere.
You wonât notice the delay until you try to control the smartme switch from another method. If you only ever use the Home Assistant switch, it will update the state right away.
I never became happy with my smartme setup because I always had this shorty flipping of the switch whenever turning on or off.
As I made some very positive experiences with the input_boolean switch I decided to give it a shot. I created an input_boolean switch and used the existing Rest Sensor to determine if the original smartme app has been used to toggle the switch. I kept my command line switch but I leave the state update to the input_boolean.
#automations.yaml
- id: SmartMe Switch Boolean API from on to off
alias: 'Smart-Me Switch api toggles from on to off'
trigger:
- entity_id: sensor.smartmeterswitchon
from: 'True'
platform: state
to: 'False'
action:
- entity_id: input_boolean.notify_smartme_switch_pool_pumpe
service: input_boolean.turn_off
- id: SmartMe Switch Boolean API from off to on
alias: 'Smart-Me Switch api toggles from off to on'
trigger:
- entity_id: sensor.smartmeterswitchon
from: 'False'
platform: state
to: 'True'
action:
- entity_id: input_boolean.notify_smartme_switch_pool_pumpe
service: input_boolean.turn_on
- id: SmartMe switch on to off based on input boolean
alias: 'SmartMe switch on to off based on input boolean'
trigger:
- entity_id: input_boolean.notify_smartme_switch_pool_pumpe
from: 'on'
platform: state
to: 'off'
action:
- entity_id: switch.smartmeswitch
service: switch.turn_off
- id: SmartMe switch off to on based on input boolean
alias: 'SmartMe switch off to on based on input boolean'
trigger:
- entity_id: input_boolean.notify_smartme_switch_pool_pumpe
from: 'off'
platform: state
to: 'on'
action:
- entity_id: switch.smartmeswitch
service: switch.turn_on
I only use the input boolean switch to switch the state from HA. This way the state is always up to date and doesnât flip to the wrong state for a second.
I finally found the solution to use the switches on Smart-Me. On their API thereâs one resource to SET the action and another resource to GET the state of the device. â> use"state_resource"
Hereâs the code, just make sure to use the correct device-ID (3 times):
and if youâre silly enough to buy the overpriced smart-me-plug:
use ObisCode 63000C0101FF to get SwitchOn
Additional reminder (for whoever ends up on this topic using google):
You could get the DeviceID on the Smart-Meâs API-Website, try the GET /api/Devices: smart-me REST API
Donât forget to insert your login at the top-right corner.
Thereâs only one ugly thing I could not solve yet: If you toggle the switch on homeassistant, it does not wait for the action to be set and updates the âstate_resourceâ instantly. After that, your switch on homeassistant drops back to the initial state for about 30 sec, until it gets finally updated by the correct state. I donât see any option to set a delay on the REST-switches