Foscam camera with lots of controls

hadnt seen that, and i dont play around with settings that much :wink:

i changed it in the app.
you could copy the whole app or edit yours.

line 204 was:

      data = urlopen(self.url + "set" + kwargs["settingstype"] + "&" + kwargs["settingstype"].lower() + "=" + new).read().decode()

and that is now:

      if kwargs["settingstype"] == "Contrast":
        data = urlopen(self.url + "setContrast&constrast=" + new).read().decode()
      else:
        data = urlopen(self.url + "set" + kwargs["settingstype"] + "&" + kwargs["settingstype"].lower() + "=" + new).read().decode()

@thundergreen
i expected that you knew that changes on HA yaml needs a restart from HA completely.
if you havent done that, then its no wonder that there are no input_sliders.
but i wanted to see the configuration.yaml from HA.
you need to have the input_slider set in there too, and i wanted to make sure you have it set there right.
do you see your other input_sliders? (from your alarm clock)


homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 48.9771094
  longitude: 2.8721844
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 79
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/Paris
  # customize
  customize: !include customize.yaml
##### Web-Front_end Config##

config:

##### Android IP Cam ###

# android_ip_webcam:
#   - host: 192.168.1.34
#   - host: 192.168.1.17
#  port: 8080

# Show links to resources in log and frontend
# introduction:

# Zeroconf
zeroconf:

# FFMPEG - AVCONV Fork for Raspbian
ffmpeg:
  ffmpeg_bin: /usr/bin/avconv

# Cam

# camera:
#   - platform: mjpeg
#     name: Cam Phone Thorsten
#     mjpeg_url: http://192.168.1.28:8082
#     still_image_url: http://192.168.1.28/picture/2/current/
camera:
  - platform: foscam
    ip: 192.168.1.201
    username: 'thundergreen'
    password: '%%LogMeIn%%'
  # - platform: rpi_camera
#   - platform: mjpeg
#     name: Cam Tablet
#     mjpeg_url: http://192.168.1.28:8083
#     still_image_url: http://192.168.1.28/picture/3/current/
#     #image_rotation: 180
#     image_quality: 80
# camera 2:
#   - platform: generic
#     name: Emilie
#     still_image_url: https://maps.googleapis.com/maps/api/staticmap?center={{ states.device_tracker.pi_thorsten.attributes.latitude }},{{ states.device_tracker.pi_thorsten.attributes.longitude }},{{ states.device_tracker.pi_emilie.attributes.latitude }},{{ states.device_tracker.pi_emilie.attributes.longitude }}&zoom=13&size=500x500&maptype=roadmap&markers=color:blue%7Clabel:P%7C{{ states.device_tracker.pi_thorsten.attributes.latitude }},{{ states.device_tracker.pi_thorsten.attributes.longitude }},{{ states.device_tracker.pi_emilie.attributes.latitude }},{{ states.device_tracker.pi_emilie.attributes.longitude }}
#     limit_refetch_to_url_change: true

############# INFLUX TEST #########
influxdb:
  host: 192.168.1.234

# OpenALPR for registration plate recognition
# openalpr:
#   engine: local
#   region: eu
#   confidence: 50.0
#   alpr_binary: /usr/bin/alpr
#   entities:
#     - name: Camera Garage
#       interval: 5
#       render: image
#       input: http://192.168.1.28/picture/1/current/

## Logger

logger:
  default: error

# Switches

switch: !include switches.yaml

# Groups
group: !include groups.yaml

# Enables the frontend
frontend:

# Binary Sensors
binary_sensor: !include binary_sensors.yaml



http:
  # Uncomment this to add a password (recommended!)
  api_password: !secret http_password
  trusted_networks:
    - 127.0.0.1
    - 192.168.1.22
    - 192.168.1.48
    - 192.168.1.28

  # Uncomment this if you are using SSL or running in Docker etc
  # base_url: https://emevth.no-ip.biz

# Checks for available updates
updater:

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time.
history:

# Enable Recorder
recorder:
  purge_days: 5
  db_url: mysql://hass:[email protected]/homeassistant

# View all events in a logbook
logbook:

# Track the sun
sun:

# Automations
automation: !include_dir_merge_list automation/

# Scripts
script: !include scripts.yaml

#### SCENES #####
scene: !include scenes.yaml

# Weather Prediction
sensor: !include sensors.yaml

# Shell Commands
shell_command: !include shell_commands.yaml

# Input Boolean
input_boolean: !include input_boolean.yaml


# Text to speech
tts:
  - platform: google
    cache: true
    cache_dir: /home/hass/.homeassistant/tts
    time_memory: 300
  - platform: picotts
    language: 'de-DE'
#  language: 'fr'

# Notify Services
notify: !include service_notify.yaml

# Device Tracker
device_tracker: !include device_tracker.yaml

# Input Select
input_select: !include input_select.yaml

# Image processing
# image_processing:
#  - platform: openalpr_local
#    region: eu
#    source:
#     - entity_id: camera.cam_garage
# Z-Wave AeonTech Gen 5
zwave:
  device_config: !include zwave_device_config.yaml
  usb_path: /dev/ttyACM0
  config_path: /srv/hass/hass_venv/lib/python3.4/site-packages/libopenzwave-0.3.1-py3.4-linux-armv7l.egg/config
  polling_interval: 60000
  # # customize:
  #   lock.main_door_locked_2_0:
  #     polling_intensity: 1


### Custom Panels ###

##### Arduino Board
# arduino:
#   port: /dev/ttyACM0
#panel_custom:
#  - name: dmp
#    sidebar_title: Digital Movie Poster
#    sidebar_icon: mdi:movie
#    config:
#      kodi: 'media_player.kodi'
#      api_pwd: xxxxxx'


### Panel I-Frame ###

panel_iframe:
  router:
    title: 'Router'
    icon: 'mdi:router-wireless'
    url: 'http://192.168.1.1'
  ip_cam:
    title: 'Security Cam'
    icon: 'mdi:webcam'
    url: 'http://192.168.1.28'
  grafana:
    title: 'Grafana Graphs'
    icon: 'mdi:chart-areaspline'
    url: 'http://192.168.1.234:3000'
  backup:
    title: 'Backup System'
    icon: 'mdi:backup-restore'
    url: 'http://192.168.1.234:55414'
#  kodi_mediacenter:
#    title: Media Center
#    icon: 'mdi:kodi'
#    url: 'http://192.168.1.40:8080/'
#  ozwcp:
#    title: Open Z-wave Control Panel
#    icon: 'mdi:access-point'
#    url: 'http://192.168.1.22:8090/'
#  dashboard:
#    title: Dashboard
#    url: 'http://emevth.no-ip.biz:5050/MainPanel?skin=hygge'

# Mutlimedia
media_player:
  - platform: kodi
    host: 192.168.1.40
    port: 8080
    enable_websocket: false
    turn_off_action: reboot
    tcp_port: 9090
    name: Kodi
  - platform: cast
  - platform: lg_netcast
    host: 192.168.1.27
    access_token: 399887
  # - platform: plex
  #   ip_address: 192.168.1.234
  #   entity_namespace: 'plex'
  #   include_non_clients: true
  #   scan_interval: 5
  #   show_all_controls: true
  #   use_custom_entity_ids: true
  #   use_episode_art: true


# MQTT Broker
mqtt:
  discovery: true
  discovery_prefix: homeassistant-MQTT
  broker: localhost
  port: 1883
  client_id: home-assistant-1
  keepalive: 60
  username: pi
  password: raspberry

# Alarm Control Panel
alarm_control_panel:
  - platform: manual
    name: "Alarmsystem"
    code: 11122012
    pending_time: 60
    trigger_time: 120
    disarm_after_trigger: true

# Light Platforms

# Philips Hue Platform
light:
  - platform: hue
    host: 192.168.1.38
    allow_unreachable: true
    #scan_interval: 10
    # allow_hue_groups: true


# Hyperion Light

  - platform: hyperion
    host: 192.168.1.40
    port: 19444

# Piglow
  - platform: piglow

# Battery State
battery_state:

# Zones
zone:
  - name: work_thorsten
    latitude: 48.8768868
    longitude: 2.3069316
    radius: 250
    icon: mdi:worker
  - name: work_emilie
    latitude: 48.9874818
    longitude: 2.538180
    radius: 250
    icon: mdi:worker
  - name: home
    latitude: 48.9771094
    longitude: 2.8721844
    radius: 250
    icon: mdi:home-map-marker

I will restart hass another time after creating the input sliders. Is my configuration.yaml ok ?

Anyway… my input_select won’t be shown in hass. Already restarted after adding those… I dont see whats wrong here

you dont have:

input_slider: !include input_slider.yaml

thats why your inputsliders wont show up :wink:

… wow… u r right … dunno how this could disappear in the config :stuck_out_tongue:

I am restarting hass. will let u know

OK… I put in the input slider but error log wont show anything but:

pi@home-assistant:~/appdaemon_dashboard/appdaemon/conf $ tail -f /home/pi/appdaemon_dashboard/appdae
mon/logs/appdaemon_error.log
    init_object(name, class_name, module_name, config[name])
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 592, in init_object
    conf.objects[name]["object"].initialize()
  File "/home/pi/appdaemon_dashboard/appdaemon/conf/apps/foscam.py", line 88, in initialize
    self.run_every(self.get_sensors,runtime,repeat)
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appapi.py", line 516, in run_every
    raise ValueError("start cannot be in the past")
ValueError: start cannot be in the past

and

^Cpi@home-assistant:~/appdaemon_dashboard/appdaemon/conf $ tail -f /home/pi/appdaemon_dashboard/appdmon/logs/appdaemon.log
2017-05-09 15:46:47.101396 INFO foscam: devstate gaf foute data
2017-05-09 15:46:47.207275 INFO foscam: image setting gaf foute data
2017-05-09 15:46:57.115778 INFO foscam: devstate gaf foute data
2017-05-09 15:46:57.245078 INFO foscam: image setting gaf foute data
2017-05-09 15:47:07.093549 INFO foscam: devstate gaf foute data
2017-05-09 15:47:07.203678 INFO foscam: image setting gaf foute data
2017-05-09 15:47:17.113663 INFO foscam: devstate gaf foute data
2017-05-09 15:47:17.189825 INFO foscam: image setting gaf foute data
2017-05-09 15:47:27.089594 INFO foscam: devstate gaf foute data
2017-05-09 15:47:27.175971 INFO foscam: image setting gaf foute data
2017-05-09 15:47:37.116695 INFO foscam: devstate gaf foute data
2017-05-09 15:47:37.196277 INFO foscam: image setting gaf foute data
2017-05-09 15:47:47.145392 INFO foscam: devstate gaf foute data
2017-05-09 15:47:47.272666 INFO foscam: image setting gaf foute data
2017-05-09 15:47:57.129565 INFO foscam: devstate gaf foute data
2017-05-09 15:47:57.195847 INFO foscam: image setting gaf foute data
2017-05-09 15:48:07.073938 INFO foscam: devstate gaf foute data
2017-05-09 15:48:07.189146 INFO foscam: image setting gaf foute data
2017-05-09 15:48:17.130118 INFO foscam: devstate gaf foute data
2017-05-09 15:48:17.217689 INFO foscam: image setting gaf foute data
2017-05-09 15:48:27.118967 INFO foscam: devstate gaf foute data
2017-05-09 15:48:27.206675 INFO foscam: image setting gaf foute data
2017-05-09 15:48:37.114539 INFO foscam: devstate gaf foute data
2017-05-09 15:48:37.231454 INFO foscam: image setting gaf foute data
2017-05-09 15:48:47.329361 INFO foscam: devstate gaf foute data
2017-05-09 15:48:47.487533 INFO foscam: image setting gaf foute data
2017-05-09 15:48:57.079469 INFO foscam: devstate gaf foute data
2017-05-09 15:48:57.148668 INFO foscam: image setting gaf foute data
2017-05-09 15:49:07.145446 INFO foscam: devstate gaf foute data
2017-05-09 15:49:07.258408 INFO foscam: image setting gaf foute data

Do u know if special characters like % could harm ?

seems to work …

i think your device is a little to slow.
i didnt put in a delay for the run-in

in the app find the line:

    runtime = datetime.datetime.now()

and make it:

    runtime = datetime.datetime.now() + datetime.timedelta(seconds=5)

after that restart appdaemon.
that should get the error away.

and please show your appdaemon.cfg, because i think there must be another problem if you get that error every 10 seconds.

in foscam.py?

2017-05-09 16:27:13.409768 INFO AppDaemon Version 2.0.0beta3.5 starting
2017-05-09 16:27:19.651046 INFO Got initial state
2017-05-09 16:27:19.659801 INFO Loading Module: /home/pi/appdaemon_dashboard/appdaemon/conf/apps/foscam.py
2017-05-09 16:27:19.721232 INFO Loading Object foscam using class foscam from module foscam
2017-05-09 16:27:19.741905 INFO Loading Module: /home/pi/appdaemon_dashboard/appdaemon/conf/apps/hello.py
2017-05-09 16:27:19.749231 INFO Loading Object hello_world using class HelloWorld from module hello
2017-05-09 16:27:20.225108 INFO hello_world: Hello from AppDaemon
2017-05-09 16:27:20.235275 INFO hello_world: You are now ready to run Apps!
2017-05-09 16:27:20.237611 INFO App initialization complete
2017-05-09 16:27:20.240991 INFO Starting dashboard
2017-05-09 16:27:20.290330 INFO HADashboard Started
2017-05-09 16:27:20.292389 INFO Listening on ('192.168.1.22', 5050)
2017-05-09 16:27:20.318999 INFO Connected to Home Assistant 0.44.1
2017-05-09 16:27:24.130679 INFO foscam: devstate gaf foute data
2017-05-09 16:27:24.247420 INFO foscam: image setting gaf foute data

thats the config:

[foscam]
module = foscam
class = foscam
host = 192.168.1.201
port = 88
user = xxxx
password = xxxx
sensor_update_time = 10
motion_sensor = sensor.foscam_motion
recording_sensor = sensor.foscam_recording
soundalarm_sensor = sensor.foscam_sound_alarm
up_down_slider = input_slider.foscam_up_down
left_right_slider = input_slider.foscam_left_right
infrared_switch = input_boolean.foscam_infrared
auto_infrared_switch = input_boolean.foscam_auto_infrared
motion_switch = input_boolean.foscam_motion_detect
zoom_slider = input_slider.foscam_zoom
preset_points_select = input_select.foscam_preset_points
start_cruise_select = input_select.foscam_preset_cruise
stop_cruise_switch = input_boolean.foscam_stop_cruise
brightness_slider = input_slider.foscam_brightness
contrast_slider = input_slider.foscam_contrast
hue_slider = input_slider.foscam_hue
saturation_slider = input_slider.foscam_saturation
sharpness_slider = input_slider.foscam_sharpness
default_pic_settings_switch = input_boolean.foscam_default_picture_settings
mirror_switch = input_boolean.foscam_mirror
flip_switch = input_boolean.foscam_flip
snap_picture_switch = input_boolean.foscam_snap_picture_now
save_snap_dir = /home/hass/.homeassistant/foscam_snap/

oke, thats all correct.
i remember 1 thing.

did you install untangle, and in the same env as appdaemon?

pip3 install untangle

Yes I did. Appdaemon doesn’t run in venv so I installed untangle system wide with pip3 install untangle after I got the python error for missing untangle

do you still get the lines:

2017-05-09 16:27:24.130679 INFO foscam: devstate gaf foute data
2017-05-09 16:27:24.247420 INFO foscam: image setting gaf foute data

every 10 seconds?
if so could you edit foscam.py and blind out some lines for me?

in this function:

  def get_sensors(self, kwargs):
    #self.log(self.url + "getDevState")
    #try:   #<=THIS LINE
      DevState = untangle.parse(self.url + "getDevState")
      motion_alarm = DevState.CGI_Result.motionDetectAlarm.cdata  # 0-Disabled, 1-No Alarm, 2-Detect Alarm
      self.set_state(self.motion_sensor,state = motion_alarm)
      if motion_alarm == "0":
        self.turn_off(self.motion_switch)
      else:
        self.turn_on(self.motion_switch)
      sound_alarm = DevState.CGI_Result.soundAlarm.cdata  # 0-Disabled, 1-No Alarm, 2-Detect Alarm
      self.set_state(self.soundalarm_sensor,state = sound_alarm)
      recording = DevState.CGI_Result.record.cdata  # 0-not recording, 1-recording
      self.set_state(self.recording_sensor,state = recording)
      infrared = DevState.CGI_Result.infraLedState.cdata  # 0-Off, 1-On
      if infrared == "0":
        self.turn_off(self.infrared_switch)
      else:
        self.turn_on(self.infrared_switch)
    #except:  #<=THIS LINE
      #self.log("devstate gaf foute data")  #<=THIS LINE
    #try:  #<=THIS LINE
      pic_settings = untangle.parse(self.url + "getImageSetting")
      brightness = pic_settings.CGI_Result.brightness.cdata 
      contrast = pic_settings.CGI_Result.contrast.cdata  
      hue = pic_settings.CGI_Result.hue.cdata 
      saturation = pic_settings.CGI_Result.saturation.cdata  
      sharpness = pic_settings.CGI_Result.sharpness.cdata
      self.call_service("input_slider/select_value", entity_id=(self.brightness_slider), value=brightness)
      self.call_service("input_slider/select_value", entity_id=(self.contrast_slider), value=contrast)
      self.call_service("input_slider/select_value", entity_id=(self.hue_slider), value=hue)
      self.call_service("input_slider/select_value", entity_id=(self.saturation_slider), value=saturation)
      self.call_service("input_slider/select_value", entity_id=(self.sharpness_slider), value=sharpness)  
    #except:  #<=THIS LINE
      #self.log("image setting gaf foute data")  #<=THIS LINE

edit the lines i marked with #<=THIS LINE

after you saved that, you dont need to restart AD
and please give me the log after 30 seconds or so.
i want to know what errors come up.

(and forgive me that i dont have a nicer debuging way, i am not a real programmer and this was only a first version :wink: )

Ok mate.will try that and let u know.thanks so far.awesome work indeed!;):+1:

1 Like

now it get:


2017-05-09 21:13:30.081359 WARNING ------------------------------------------------------------
2017-05-09 21:13:30.083744 WARNING Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 514, in worker
    function(ha.sanitize_timer_kwargs(args["kwargs"]))
  File "/home/pi/appdaemon_dashboard/appdaemon/conf/apps/foscam.py", line 112, in get_sensors
    motion_alarm = DevState.CGI_Result.motionDetectAlarm.cdata  # 0-Disabled, 1-No Alarm, 2-Detect Alarm
  File "/usr/local/lib/python3.4/dist-packages/untangle.py", line 66, in __getattr__
    raise IndexError('Unknown key <%s>' % key)
IndexError: Unknown key <motionDetectAlarm>

2017-05-09 21:13:30.085071 WARNING ------------------------------------------------------------
---------------
2017-05-09 21:15:50.078744 WARNING Unexpected error in worker for App foscam:
2017-05-09 21:15:50.080639 WARNING Worker Ags: {'id': UUID('36fc7950-ce2c-47da-8a71-34fccb9ebfe9'), 'type': 'timer', 'function': <bound method foscam.get_sensors of <foscam.foscam object at 0x75bc5c70>>, 'name': 'foscam', 'kwargs': {'interval': 10}}
2017-05-09 21:15:50.082136 WARNING -

but if i see it right you only get the error once in a while.

you got it 21:13:30 and again on 21:15:50
so not every 10 seconds like before.

thats expected behaviour. i dont know what the cam sends, but at some moments the data isnt complete or deformed somehow.

at some periods i get the warning 5 times in 5 miutes then i dont get it for hours.
the warning is only there to show you how many times the sensors couldnt be updated.

in the version i am working on the second warning is going to zero, because i only collect the devicedata at the start of the app. after that only the sensors get pulled every 10 seconds.

if the warning is annoying you can replace the line:

self.log("devstate gaf foute data")

with

return

after you did set things back to how they were :wink:

the problem is that the sliders and stuff wont work at all

the error appears all 5 seconds … i just badly copied and pasted here :stuck_out_tongue: well… the functions in hass are zero… so no function for me :frowning:

I think i know whats failing!!! it is indeed the % sign in my password!